use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class DiskStorageCacheTest method testInsertionInIndex.
@Test
public void testInsertionInIndex() throws Exception {
CacheKey key = putOneThingInCache();
assertTrue(mCache.hasKeySync(key));
assertTrue(mCache.hasKey(key));
}
use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class DiskStorageCacheTest method testSizeEvictionClearsIndex.
@Test
public void testSizeEvictionClearsIndex() throws Exception {
when(mClock.now()).thenReturn(TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS));
CacheKey key1 = putOneThingInCache();
CacheKey key2 = new SimpleCacheKey("bar");
CacheKey key3 = new SimpleCacheKey("duck");
byte[] value2 = new byte[(int) FILE_CACHE_MAX_SIZE_HIGH_LIMIT];
value2[80] = 'c';
WriterCallback callback = WriterCallbacks.from(value2);
when(mClock.now()).thenReturn(TimeUnit.MILLISECONDS.convert(2, TimeUnit.DAYS));
mCache.insert(key2, callback);
// now over limit. Next write will evict key1
when(mClock.now()).thenReturn(TimeUnit.MILLISECONDS.convert(3, TimeUnit.DAYS));
mCache.insert(key3, callback);
assertFalse(mCache.hasKeySync(key1));
assertFalse(mCache.hasKey(key1));
assertTrue(mCache.hasKeySync(key3));
assertTrue(mCache.hasKey(key3));
}
use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class DiskStorageCacheTest method testCleanOldCacheNoEntriesRemaining.
@Test
public void testCleanOldCacheNoEntriesRemaining() throws IOException {
long cacheExpirationMs = TimeUnit.DAYS.toMillis(5);
CacheKey key1 = new SimpleCacheKey("aaa");
byte[] value1 = new byte[41];
mCache.insert(key1, WriterCallbacks.from(value1));
CacheKey key2 = new SimpleCacheKey("bbb");
byte[] value2 = new byte[42];
mCache.insert(key2, WriterCallbacks.from(value2));
// Increment clock by default expiration time + 1 day
when(mClock.now()).thenReturn(cacheExpirationMs + TimeUnit.DAYS.toMillis(1));
long oldestEntry = mCache.clearOldEntries(cacheExpirationMs);
assertEquals(0L, oldestEntry);
}
use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class DiskStorageCacheTest method testHasKeyWithoutPopulateAtStartupWithoutAwaitingIndex.
@Test
public void testHasKeyWithoutPopulateAtStartupWithoutAwaitingIndex() throws Exception {
CacheKey key = putOneThingInCache();
// A new cache object in the same directory. Equivalent to a process restart.
// Index may not yet updated.
DiskStorageCache cache2 = createDiskCache(mStorage, false);
assertTrue(cache2.isIndexReady());
assertFalse(cache2.hasKeySync(key));
assertTrue(cache2.hasKey(key));
// hasKey() adds item to the index
assertTrue(cache2.hasKeySync(key));
}
use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class BaseFrescoStethoPlugin method memcache.
private void memcache(PrintStream writer, List<String> args) throws DumpException {
CountingMemoryCacheInspector.DumpInfo<CacheKey, CloseableImage> dumpInfo = mBitmapMemoryCacheInspector.dumpCacheContent();
try {
writer.println(mBitmapMemoryCacheInspector.getClass().getSimpleName());
writer.println();
writer.println("Params:");
writer.println(formatStrLocaleSafe("Max size: %7.2fMB", dumpInfo.maxSize / (1024.0 * KB)));
writer.println(formatStrLocaleSafe("Max entries count: %9d", dumpInfo.maxEntriesCount));
writer.println(formatStrLocaleSafe("Max entry size: %7.2fMB", dumpInfo.maxEntrySize / (1024.0 * KB)));
writer.println();
writer.println("Summary of current content:");
writer.println(formatStrLocaleSafe("Total size: %7.2fMB (includes in-use content)", dumpInfo.size / (1024.0 * KB)));
writer.println(formatStrLocaleSafe("Entries count: %9d", dumpInfo.lruEntries.size() + dumpInfo.sharedEntries.size()));
writer.println(formatStrLocaleSafe("LRU size: %7.2fMB", dumpInfo.lruSize / (1024.0 * KB)));
writer.println(formatStrLocaleSafe("LRU count: %9d", dumpInfo.lruEntries.size()));
writer.println(formatStrLocaleSafe("Shared size: %7.2fMB", (dumpInfo.size - dumpInfo.lruSize) / (1024.0 * KB)));
writer.println(formatStrLocaleSafe("Shared count: %9d", dumpInfo.sharedEntries.size()));
writer.println();
writer.println("The cache consists of two parts: Things " + "currently being used and things not.");
writer.println("Those things that are *not* currently being used are in the LRU.");
writer.println("Things currently being used are considered to be shared. They will be added");
writer.println("to the LRU if/when they stop being used.");
writer.println();
writer.println("LRU contents: (things near the top will be evicted first)");
for (CountingMemoryCacheInspector.DumpInfoEntry entry : dumpInfo.lruEntries) {
writeCacheEntry(writer, entry);
}
writer.println();
writer.println("Shared contents:");
for (CountingMemoryCacheInspector.DumpInfoEntry entry : dumpInfo.sharedEntries) {
writeCacheEntry(writer, entry);
}
if (!args.isEmpty() && "-g".equals(args.get(0))) {
getFiles(writer, dumpInfo);
}
} catch (IOException e) {
throw new DumpException(e.getMessage());
} finally {
dumpInfo.release();
}
}
Aggregations