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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations