Search in sources :

Example 21 with SimpleCacheKey

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

the class DiskStorageCacheTest method putOneThingInCache.

private CacheKey putOneThingInCache(DiskStorageCache cache) throws IOException {
    CacheKey key = new SimpleCacheKey("foo");
    byte[] value1 = new byte[101];
    value1[80] = 'c';
    cache.insert(key, WriterCallbacks.from(value1));
    return key;
}
Also used : SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey)

Example 22 with SimpleCacheKey

use of com.facebook.cache.common.SimpleCacheKey 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);
}
Also used : SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest) Test(org.junit.Test)

Example 23 with SimpleCacheKey

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

the class PostprocessedBitmapMemoryCacheProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mMemoryCacheProducer = new PostprocessedBitmapMemoryCacheProducer(mMemoryCache, mCacheKeyFactory, mInputProducer);
    mPostProcessorCacheKey = new SimpleCacheKey("blur");
    mPostprocessedBitmapCacheKey = new SimpleCacheKey("http://dummy.uri:blur");
    mImageRef2 = CloseableReference.of(mImage1);
    mImageRef1 = CloseableReference.of(mImage2);
    mImageRef2Clone = mImageRef2.clone();
    mImageRef1Clone = mImageRef1.clone();
    when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
    when(mProducerContext.getListener()).thenReturn(mProducerListener);
    when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
    when(mProducerContext.getId()).thenReturn(mRequestId);
    when(mProducerContext.getCallerContext()).thenReturn(PRODUCER_NAME);
    when(mImageRequest.getPostprocessor()).thenReturn(mPostprocessor);
    when(mPostprocessor.getPostprocessorCacheKey()).thenReturn(mPostProcessorCacheKey);
    when(mRepeatedPostprocessor.getPostprocessorCacheKey()).thenReturn(mPostProcessorCacheKey);
    when(mCacheKeyFactory.getPostprocessedBitmapCacheKey(mImageRequest, PRODUCER_NAME)).thenReturn(mPostprocessedBitmapCacheKey);
}
Also used : SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey)

Example 24 with SimpleCacheKey

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

the class DiskCacheReadProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mDiskCacheReadProducer = new DiskCacheReadProducer(mInputProducer, mDiskCachePolicy);
    List<CacheKey> keys = new ArrayList<>(1);
    keys.add(new SimpleCacheKey("http://dummy.uri"));
    mCacheKey = new MultiCacheKey(keys);
    mIntermediatePooledByteBuffer = mock(PooledByteBuffer.class);
    mFinalPooledByteBuffer = mock(PooledByteBuffer.class);
    mIntermediateImageReference = CloseableReference.of(mIntermediatePooledByteBuffer);
    mFinalImageReference = CloseableReference.of(mFinalPooledByteBuffer);
    mIntermediateEncodedImage = new EncodedImage(mIntermediateImageReference);
    mFinalEncodedImage = new EncodedImage(mFinalImageReference);
    mIsCancelled = ArgumentCaptor.forClass(AtomicBoolean.class);
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM);
    mLowestLevelProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.DISK_CACHE, false, true, Priority.MEDIUM);
    when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);
    when(mImageRequest.getCacheChoice()).thenReturn(ImageRequest.CacheChoice.DEFAULT);
    when(mImageRequest.isDiskCacheEnabled()).thenReturn(true);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) ArrayList(java.util.ArrayList) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) 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)

Example 25 with SimpleCacheKey

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

the class EncodedMemoryCacheProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mEncodedMemoryCacheProducer = new EncodedMemoryCacheProducer(mMemoryCache, mCacheKeyFactory, mInputProducer);
    mPooledByteBuffer1 = mock(PooledByteBuffer.class);
    mPooledByteBuffer2 = mock(PooledByteBuffer.class);
    mFinalImageReference = CloseableReference.of(mPooledByteBuffer1);
    mIntermediateImageReference = CloseableReference.of(mPooledByteBuffer2);
    mFinalImageReferenceClone = mFinalImageReference.clone();
    mFinalEncodedImage = new EncodedImage(mFinalImageReference);
    mIntermediateEncodedImage = new EncodedImage(mIntermediateImageReference);
    mFinalEncodedImageClone = new EncodedImage(mFinalImageReferenceClone);
    List<CacheKey> list = new ArrayList<>();
    list.add(new SimpleCacheKey("http://dummy.uri"));
    mCacheKey = new MultiCacheKey(list);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);
    when(mMemoryCache.cache(mCacheKey, mFinalImageReference)).thenReturn(mFinalImageReferenceClone);
    when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
    when(mProducerContext.getCallerContext()).thenReturn(mCallerContext);
    when(mProducerContext.getListener()).thenReturn(mProducerListener);
    when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
    when(mProducerContext.getId()).thenReturn(mRequestId);
    when(mProducerContext.getLowestPermittedRequestLevel()).thenReturn(ImageRequest.RequestLevel.FULL_FETCH);
}
Also used : MultiCacheKey(com.facebook.cache.common.MultiCacheKey) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) 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)

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