com.facebook.cache.common.MultiCacheKey Java Examples
The following examples show how to use
com.facebook.cache.common.MultiCacheKey.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuxCache.java From react-native-image-filter-kit with MIT License | 6 votes |
@Nonnull static CacheKey auxKey( final @Nonnull JSONObject config, final @Nonnull List<ReactImageView> images ) { final List<Integer> imageIndexes = imageIndexes(config); final ArrayList<CacheKey> keys = new ArrayList<>(); keys.add(new SimpleCacheKey(config.toString())); for (Integer index : imageIndexes) { final ImageSource source = ReactImageViewUtils.getImageSource(images.get(index)); keys.add(new SimpleCacheKey(source != null ? source.getSource() : "null")); } return new MultiCacheKey(keys); }
Example #2
Source File: DiskStorageCacheTest.java From fresco with MIT License | 6 votes |
@Test public void testWithMultiCacheKeys() throws Exception { CacheKey insertKey1 = new SimpleCacheKey("foo"); byte[] value1 = new byte[101]; value1[50] = 'a'; // just so it's not all zeros for the equality test below. mCache.insert(insertKey1, WriterCallbacks.from(value1)); List<CacheKey> keys1 = new ArrayList<>(2); keys1.add(new SimpleCacheKey("bar")); keys1.add(new SimpleCacheKey("foo")); MultiCacheKey matchingMultiKey = new MultiCacheKey(keys1); assertArrayEquals(value1, getContents(mCache.getResource(matchingMultiKey))); List<CacheKey> keys2 = new ArrayList<>(2); keys2.add(new SimpleCacheKey("one")); keys2.add(new SimpleCacheKey("two")); MultiCacheKey insertKey2 = new MultiCacheKey(keys2); byte[] value2 = new byte[101]; value1[50] = 'b'; // just so it's not all zeros for the equality test below. mCache.insert(insertKey2, WriterCallbacks.from(value2)); CacheKey matchingSimpleKey = new SimpleCacheKey("one"); assertArrayEquals(value2, getContents(mCache.getResource(matchingSimpleKey))); }
Example #3
Source File: CompositionPostProcessor.java From react-native-image-filter-kit with MIT License | 5 votes |
@Nonnull protected CacheKey compositionCacheKey(@Nonnull String prefix) { return new MultiCacheKey(Arrays.asList( new SimpleCacheKey(String.format( Locale.ROOT, "%s_%s_%s_%s_%b", prefix, mSrcTransform.toString(), mDstTransform.toString(), mResizeCanvasTo, mSwapImages )), mSrcCacheKey )); }
Example #4
Source File: FilterableImage.java From react-native-image-filter-kit with MIT License | 5 votes |
CacheKey generatedCacheKey() { final ArrayList<CacheKey> keys = new ArrayList<>( Collections.singletonList(ReactImageViewUtils.getCacheKey(mImage)) ); for (Postprocessor p : mPostProcessors) { keys.add( p instanceof CacheablePostProcessor ? ((CacheablePostProcessor) p).generateCacheKey() : p.getPostprocessorCacheKey() ); } return new MultiCacheKey(keys); }
Example #5
Source File: MultiPostprocessor.java From react-native-GPay with MIT License | 5 votes |
@Override public CacheKey getPostprocessorCacheKey () { LinkedList<CacheKey> keys = new LinkedList<>(); for (Postprocessor p: mPostprocessors) { keys.push(p.getPostprocessorCacheKey()); } return new MultiCacheKey(keys); }
Example #6
Source File: BufferedDiskCacheTest.java From fresco with MIT License | 5 votes |
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mCloseableReference = CloseableReference.of(mPooledByteBuffer); mEncodedImage = new EncodedImage(mCloseableReference); List<CacheKey> keys = new ArrayList<>(); keys.add(new SimpleCacheKey("http://test.uri")); keys.add(new SimpleCacheKey("http://tyrone.uri")); keys.add(new SimpleCacheKey("http://ian.uri")); mCacheKey = new MultiCacheKey(keys); mIsCancelled = new AtomicBoolean(false); FakeClock fakeClock = new FakeClock(); mReadPriorityExecutor = new TestExecutorService(fakeClock); mWritePriorityExecutor = new TestExecutorService(fakeClock); when(mBinaryResource.openStream()).thenReturn(mInputStream); when(mBinaryResource.size()).thenReturn(123L); when(mByteBufferFactory.newByteBuffer(same(mInputStream), eq(123))) .thenReturn(mPooledByteBuffer); mockStatic(StagingArea.class); when(StagingArea.getInstance()).thenReturn(mStagingArea); mBufferedDiskCache = new BufferedDiskCache( mFileCache, mByteBufferFactory, mPooledByteStreams, mReadPriorityExecutor, mWritePriorityExecutor, mImageCacheStatsTracker); }
Example #7
Source File: EncodedMemoryCacheProducerTest.java From fresco with MIT License | 5 votes |
@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); mFinalEncodedImage.setImageFormat(new ImageFormat("jpeg", null)); mFinalEncodedImage.setWidth(100); mFinalEncodedImage.setHeight(100); mImagePipelineConfig = mock(ImagePipelineConfig.class); mImagePipelineExperiments = mock(ImagePipelineExperiments.class); mFinalEncodedImageFormatUnknown = 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.getProducerListener()).thenReturn(mProducerListener); when(mProducerListener.requiresExtraMap(mProducerContext, PRODUCER_NAME)).thenReturn(true); when(mProducerContext.getLowestPermittedRequestLevel()) .thenReturn(ImageRequest.RequestLevel.FULL_FETCH); when(mProducerContext.getImagePipelineConfig()).thenReturn(mImagePipelineConfig); when(mImagePipelineConfig.getExperiments()).thenReturn(mImagePipelineExperiments); when(mImagePipelineExperiments.isEncodedCacheEnabled()).thenReturn(true); when(mImageRequest.isMemoryCacheEnabled()).thenReturn(true); }
Example #8
Source File: ImagePipelineTest.java From fresco with MIT License | 5 votes |
@Test public void testEvictFromDiskCache() { String uriString = "http://dummy/string"; Uri uri = Uri.parse(uriString); CacheKey dummyCacheKey = mock(CacheKey.class); List<CacheKey> list = new ArrayList<>(); list.add(dummyCacheKey); MultiCacheKey multiKey = new MultiCacheKey(list); when(mCacheKeyFactory.getEncodedCacheKey(any(ImageRequest.class), anyObject())) .thenReturn(multiKey); mImagePipeline.evictFromDiskCache(uri); verify(mMainDiskStorageCache).remove(multiKey); verify(mSmallImageDiskStorageCache).remove(multiKey); }
Example #9
Source File: DiskCacheWriteProducerTest.java From fresco with MIT License | 4 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); mDiskCacheWriteProducer = new DiskCacheWriteProducer( mDefaultBufferedDiskCache, mSmallImageBufferedDiskCache, mCacheKeyFactory, mInputProducer); 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); mFinalEncodedImageFormatUnknown = new EncodedImage(mFinalImageReference); mFinalEncodedImage = new EncodedImage(mFinalImageReference); mFinalEncodedImage.setImageFormat(new ImageFormat("jpeg", null)); mFinalEncodedImage.setWidth(100); mFinalEncodedImage.setHeight(100); mProducerContext = new SettableProducerContext( mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM, mConfig); mLowestLevelProducerContext = new SettableProducerContext( mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.DISK_CACHE, false, true, Priority.MEDIUM, mConfig); when(mProducerListener.requiresExtraMap(mProducerContext, PRODUCER_NAME)).thenReturn(true); when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey); when(mImageRequest.getCacheChoice()).thenReturn(ImageRequest.CacheChoice.DEFAULT); when(mImageRequest.isDiskCacheEnabled()).thenReturn(true); }
Example #10
Source File: DiskCacheReadProducerTest.java From fresco with MIT License | 4 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); mDiskCacheReadProducer = new DiskCacheReadProducer( mDefaultBufferedDiskCache, mSmallImageBufferedDiskCache, mCacheKeyFactory, mInputProducer); 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, mConfig); mLowestLevelProducerContext = new SettableProducerContext( mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.DISK_CACHE, false, true, Priority.MEDIUM, mConfig); when(mProducerListener.requiresExtraMap(mProducerContext, PRODUCER_NAME)).thenReturn(true); when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey); when(mImageRequest.getCacheChoice()).thenReturn(ImageRequest.CacheChoice.DEFAULT); when(mImageRequest.isDiskCacheEnabled()).thenReturn(true); }