Search in sources :

Example 11 with SimpleCacheKey

use of com.facebook.cache.common.SimpleCacheKey in project fresco by facebook.

the class AnimatedFrameCacheTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    MemoryCacheParams params = new MemoryCacheParams(4 * ByteConstants.MB, 256, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
    when(mMemoryCacheParamsSupplier.get()).thenReturn(params);
    CountingMemoryCache<CacheKey, CloseableImage> countingMemoryCache = BitmapCountingMemoryCacheFactory.get(mMemoryCacheParamsSupplier, mMemoryTrimmableRegistry, mPlatformBitmapFactory, true);
    mCacheKey = new SimpleCacheKey("key");
    mAnimatedFrameCache = new AnimatedFrameCache(mCacheKey, countingMemoryCache);
    mFrame1 = CloseableReference.of(mock(CloseableImage.class));
    mFrame2 = CloseableReference.of(mock(CloseableImage.class));
}
Also used : MemoryCacheParams(com.facebook.imagepipeline.cache.MemoryCacheParams) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) CacheKey(com.facebook.cache.common.CacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) Before(org.junit.Before)

Example 12 with SimpleCacheKey

use of com.facebook.cache.common.SimpleCacheKey in project fresco by facebook.

the class IterativeBoxBlurPostProcessor method getPostprocessorCacheKey.

@Nullable
@Override
public CacheKey getPostprocessorCacheKey() {
    if (mCacheKey == null) {
        final String key = String.format((Locale) null, "i%dr%d", mIterations, mBlurRadius);
        mCacheKey = new SimpleCacheKey(key);
    }
    return mCacheKey;
}
Also used : SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) Nullable(javax.annotation.Nullable)

Example 13 with SimpleCacheKey

use of com.facebook.cache.common.SimpleCacheKey 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)

Example 14 with SimpleCacheKey

use of com.facebook.cache.common.SimpleCacheKey in project fresco by facebook.

the class SplitCachesByImageSizeDiskCachePolicyTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    List<CacheKey> keys = new ArrayList<>(1);
    keys.add(new SimpleCacheKey("http://dummy.uri"));
    mCacheKey = new MultiCacheKey(keys);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);
    when(mImageRequest.getCacheChoice()).thenReturn(ImageRequest.CacheChoice.DEFAULT);
    when(mImageRequest.isDiskCacheEnabled()).thenReturn(true);
    mIsCancelled = new AtomicBoolean(false);
    mEncodedImage = new EncodedImage(CloseableReference.of(mImagePooledByteBuffer));
    mSplitCachesByImageSizeDiskCachePolicy = new SplitCachesByImageSizeDiskCachePolicy(mDefaultBufferedDiskCache, mSmallImageBufferedDiskCache, mCacheKeyFactory, FORCE_SMALL_CACHE_THRESHOLD);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) ArrayList(java.util.ArrayList) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) Before(org.junit.Before)

Example 15 with SimpleCacheKey

use of com.facebook.cache.common.SimpleCacheKey in project fresco by facebook.

the class StagingAreaTest method setUp.

@Before
public void setUp() {
    mStagingArea = StagingArea.getInstance();
    mCloseableReference = CloseableReference.of(mock(PooledByteBuffer.class));
    mCloseableReference2 = CloseableReference.of(mock(PooledByteBuffer.class));
    mEncodedImage = new EncodedImage(mCloseableReference);
    mSecondEncodedImage = new EncodedImage(mCloseableReference2);
    mCacheKey = new SimpleCacheKey("http://this.is/uri");
    mStagingArea.put(mCacheKey, mEncodedImage);
}
Also used : SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Aggregations

SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)26 CacheKey (com.facebook.cache.common.CacheKey)20 MultiCacheKey (com.facebook.cache.common.MultiCacheKey)19 Test (org.junit.Test)12 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)10 ArrayList (java.util.ArrayList)7 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)6 BinaryResource (com.facebook.binaryresource.BinaryResource)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Before (org.junit.Before)4 WriterCallback (com.facebook.cache.common.WriterCallback)3 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)3 Uri (android.net.Uri)2 Predicate (com.android.internal.util.Predicate)2 BitmapMemoryCacheKey (com.facebook.imagepipeline.cache.BitmapMemoryCacheKey)2 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Bitmap (android.graphics.Bitmap)1 FileBinaryResource (com.facebook.binaryresource.FileBinaryResource)1