コード例 #1
0
ファイル: ImagePipeline.java プロジェクト: Geekbruce/fresco
 /**
  * Returns whether the image is stored in the disk cache.
  *
  * @param imageRequest the imageRequest for the image to be looked up.
  * @return true if the image was found in the disk cache, false otherwise.
  */
 public DataSource<Boolean> isInDiskCache(final ImageRequest imageRequest) {
   final CacheKey cacheKey = mCacheKeyFactory.getEncodedCacheKey(imageRequest, null);
   final SimpleDataSource<Boolean> dataSource = SimpleDataSource.create();
   mMainBufferedDiskCache
       .contains(cacheKey)
       .continueWithTask(
           new Continuation<Boolean, Task<Boolean>>() {
             @Override
             public Task<Boolean> then(Task<Boolean> task) throws Exception {
               if (!task.isCancelled() && !task.isFaulted() && task.getResult()) {
                 return Task.forResult(true);
               }
               return mSmallImageBufferedDiskCache.contains(cacheKey);
             }
           })
       .continueWith(
           new Continuation<Boolean, Void>() {
             @Override
             public Void then(Task<Boolean> task) throws Exception {
               dataSource.setResult(!task.isCancelled() && !task.isFaulted() && task.getResult());
               return null;
             }
           });
   return dataSource;
 }
コード例 #2
0
  @Before
  public void setUp() {
    MockitoAnnotations.initMocks(this);
    mEncodedMemoryCacheProducer =
        new EncodedMemoryCacheProducer(mMemoryCache, mCacheKeyFactory, mNextProducer);
    mCacheKey = new SimpleCacheKey("http://dummy.uri");
    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);

    when(mMemoryCache.cache(mCacheKey, mFinalImageReference)).thenReturn(mFinalImageReferenceClone);
    when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
    when(mProducerContext.getListener()).thenReturn(mProducerListener);
    when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
    when(mProducerContext.getId()).thenReturn(mRequestId);
    when(mProducerContext.getLowestPermittedRequestLevel())
        .thenReturn(ImageRequest.RequestLevel.FULL_FETCH);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest)).thenReturn(mCacheKey);
  }
コード例 #3
0
ファイル: ImagePipeline.java プロジェクト: Geekbruce/fresco
 /**
  * Performs disk cache check synchronously. It is not recommended to use this unless you know what
  * exactly you are doing. Disk cache check is a costly operation, the call will block the caller
  * thread until the cache check is completed.
  *
  * @param imageRequest the imageRequest for the image to be looked up.
  * @return true if the image was found in the disk cache, false otherwise.
  */
 public boolean isInDiskCacheSync(final ImageRequest imageRequest) {
   final CacheKey cacheKey = mCacheKeyFactory.getEncodedCacheKey(imageRequest, null);
   return mMainBufferedDiskCache.diskCheckSync(cacheKey);
 }
コード例 #4
0
ファイル: ImagePipeline.java プロジェクト: Geekbruce/fresco
 /**
  * Removes all images with the specified {@link Uri} from disk cache.
  *
  * @param imageRequest The imageRequest for the image to evict from disk cache
  */
 public void evictFromDiskCache(final ImageRequest imageRequest) {
   CacheKey cacheKey = mCacheKeyFactory.getEncodedCacheKey(imageRequest, null);
   mMainBufferedDiskCache.remove(cacheKey);
   mSmallImageBufferedDiskCache.remove(cacheKey);
 }