use of com.facebook.imagepipeline.cache.BitmapMemoryCacheKey in project fresco by facebook.
the class ImagePipelineTest method testEvictFromMemoryCache.
@Test
public void testEvictFromMemoryCache() {
String uriString = "http://dummy/string";
Uri uri = Uri.parse(uriString);
mImagePipeline.evictFromMemoryCache(uri);
CacheKey dummyCacheKey = mock(CacheKey.class);
ArgumentCaptor<Predicate> bitmapCachePredicateCaptor = ArgumentCaptor.forClass(Predicate.class);
verify(mBitmapMemoryCache).removeAll(bitmapCachePredicateCaptor.capture());
Predicate<CacheKey> bitmapMemoryCacheKeyPredicate = bitmapCachePredicateCaptor.getValue();
BitmapMemoryCacheKey bitmapMemoryCacheKey1 = mock(BitmapMemoryCacheKey.class);
BitmapMemoryCacheKey bitmapMemoryCacheKey2 = mock(BitmapMemoryCacheKey.class);
when(bitmapMemoryCacheKey1.containsUri(uri)).thenReturn(true);
when(bitmapMemoryCacheKey2.containsUri(uri)).thenReturn(false);
assertTrue(bitmapMemoryCacheKeyPredicate.apply(bitmapMemoryCacheKey1));
assertFalse(bitmapMemoryCacheKeyPredicate.apply(bitmapMemoryCacheKey2));
assertFalse(bitmapMemoryCacheKeyPredicate.apply(dummyCacheKey));
ArgumentCaptor<Predicate> encodedMemoryCachePredicateCaptor = ArgumentCaptor.forClass(Predicate.class);
verify(mEncodedMemoryCache).removeAll(encodedMemoryCachePredicateCaptor.capture());
Predicate<CacheKey> encodedMemoryCacheKeyPredicate = encodedMemoryCachePredicateCaptor.getValue();
SimpleCacheKey simpleCacheKey1 = new SimpleCacheKey(uriString);
SimpleCacheKey simpleCacheKey2 = new SimpleCacheKey("rubbish");
assertTrue(encodedMemoryCacheKeyPredicate.apply(simpleCacheKey1));
assertFalse(encodedMemoryCacheKeyPredicate.apply(simpleCacheKey2));
assertFalse(encodedMemoryCacheKeyPredicate.apply(dummyCacheKey));
}
use of com.facebook.imagepipeline.cache.BitmapMemoryCacheKey in project fresco by facebook.
the class BaseFrescoStethoPlugin method writeCacheEntry.
private void writeCacheEntry(PrintStream writer, CountingMemoryCacheInspector.DumpInfoEntry<CacheKey, CloseableImage> entry) {
if (!(entry.key instanceof BitmapMemoryCacheKey)) {
writer.println("Undefined: " + entry.key.getClass());
}
BitmapMemoryCacheKey cacheKey = (BitmapMemoryCacheKey) entry.key;
writer.println(formatStrLocaleSafe("size: %7.2fkB (%4d x %4d) key: %s, %s, duration: %dms", entry.value.get().getSizeInBytes() / KB, entry.value.get().getWidth(), entry.value.get().getHeight(), entry.key, cacheKey.getCallerContext(), RealtimeSinceBootClock.get().now() - cacheKey.getInBitmapCacheSince()));
}
use of com.facebook.imagepipeline.cache.BitmapMemoryCacheKey in project fresco by facebook.
the class ImagePipelineTest method testClearMemoryCaches.
@Test
public void testClearMemoryCaches() {
String uriString = "http://dummy/string";
Uri uri = Uri.parse(uriString);
CacheKey dummyCacheKey = mock(CacheKey.class);
mImagePipeline.clearMemoryCaches();
ArgumentCaptor<Predicate> bitmapCachePredicateCaptor = ArgumentCaptor.forClass(Predicate.class);
verify(mBitmapMemoryCache).removeAll(bitmapCachePredicateCaptor.capture());
Predicate<CacheKey> bitmapMemoryCacheKeyPredicate = bitmapCachePredicateCaptor.getValue();
BitmapMemoryCacheKey bitmapMemoryCacheKey1 = mock(BitmapMemoryCacheKey.class);
BitmapMemoryCacheKey bitmapMemoryCacheKey2 = mock(BitmapMemoryCacheKey.class);
when(bitmapMemoryCacheKey1.containsUri(uri)).thenReturn(true);
when(bitmapMemoryCacheKey2.containsUri(uri)).thenReturn(false);
assertTrue(bitmapMemoryCacheKeyPredicate.apply(bitmapMemoryCacheKey1));
assertTrue(bitmapMemoryCacheKeyPredicate.apply(bitmapMemoryCacheKey2));
assertTrue(bitmapMemoryCacheKeyPredicate.apply(dummyCacheKey));
ArgumentCaptor<Predicate> encodedMemoryCachePredicateCaptor = ArgumentCaptor.forClass(Predicate.class);
verify(mEncodedMemoryCache).removeAll(encodedMemoryCachePredicateCaptor.capture());
Predicate<CacheKey> encodedMemoryCacheKeyPredicate = encodedMemoryCachePredicateCaptor.getValue();
SimpleCacheKey simpleCacheKey1 = new SimpleCacheKey(uriString);
SimpleCacheKey simpleCacheKey2 = new SimpleCacheKey("rubbish");
assertTrue(encodedMemoryCacheKeyPredicate.apply(simpleCacheKey1));
assertTrue(encodedMemoryCacheKeyPredicate.apply(simpleCacheKey2));
assertTrue(encodedMemoryCacheKeyPredicate.apply(dummyCacheKey));
}
Aggregations