Search in sources :

Example 1 with BitmapMemoryCacheKey

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));
}
Also used : SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) BitmapMemoryCacheKey(com.facebook.imagepipeline.cache.BitmapMemoryCacheKey) Uri(android.net.Uri) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) BitmapMemoryCacheKey(com.facebook.imagepipeline.cache.BitmapMemoryCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) Predicate(com.android.internal.util.Predicate) Test(org.junit.Test)

Example 2 with BitmapMemoryCacheKey

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()));
}
Also used : BitmapMemoryCacheKey(com.facebook.imagepipeline.cache.BitmapMemoryCacheKey)

Example 3 with BitmapMemoryCacheKey

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));
}
Also used : SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) BitmapMemoryCacheKey(com.facebook.imagepipeline.cache.BitmapMemoryCacheKey) Uri(android.net.Uri) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) BitmapMemoryCacheKey(com.facebook.imagepipeline.cache.BitmapMemoryCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) Predicate(com.android.internal.util.Predicate) Test(org.junit.Test)

Aggregations

BitmapMemoryCacheKey (com.facebook.imagepipeline.cache.BitmapMemoryCacheKey)3 Uri (android.net.Uri)2 Predicate (com.android.internal.util.Predicate)2 CacheKey (com.facebook.cache.common.CacheKey)2 MultiCacheKey (com.facebook.cache.common.MultiCacheKey)2 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)2 Test (org.junit.Test)2