コード例 #1
0
 private CacheKey getCacheKey() {
   final ImageRequest imageRequest = getImageRequest();
   final CacheKeyFactory cacheKeyFactory = mImagePipeline.getCacheKeyFactory();
   CacheKey cacheKey = null;
   if (cacheKeyFactory != null && imageRequest != null) {
     if (imageRequest.getPostprocessor() != null) {
       cacheKey = cacheKeyFactory.getPostprocessedBitmapCacheKey(imageRequest, getCallerContext());
     } else {
       cacheKey = cacheKeyFactory.getBitmapCacheKey(imageRequest, getCallerContext());
     }
   }
   return cacheKey;
 }
コード例 #2
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;
 }
コード例 #3
0
ファイル: ImagePipeline.java プロジェクト: Geekbruce/fresco
 /**
  * Returns whether the image is stored in the bitmap memory cache.
  *
  * @param imageRequest the imageRequest for the image to be looked up.
  * @return true if the image was found in the bitmap memory cache, false otherwise.
  */
 public boolean isInBitmapMemoryCache(final ImageRequest imageRequest) {
   if (imageRequest == null) {
     return false;
   }
   final CacheKey cacheKey = mCacheKeyFactory.getBitmapCacheKey(imageRequest, null);
   CloseableReference<CloseableImage> ref = mBitmapMemoryCache.get(cacheKey);
   try {
     return CloseableReference.isValid(ref);
   } finally {
     CloseableReference.closeSafely(ref);
   }
 }
コード例 #4
0
  @Before
  public void setUp() {
    MockitoAnnotations.initMocks(this);
    mBitmapMemoryCacheGetProducer =
        new BitmapMemoryCacheGetProducer(mMemoryCache, mCacheKeyFactory, mInputProducer);
    mCloseableImage1 = mock(CloseableImage.class);
    mFinalImageReference = CloseableReference.of(mCloseableImage1);
    when(mCloseableImage1.getQualityInfo()).thenReturn(ImmutableQualityInfo.FULL_QUALITY);

    when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
    when(mProducerContext.getListener()).thenReturn(mProducerListener);
    when(mProducerContext.getId()).thenReturn(mRequestId);
    when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
    when(mProducerContext.getLowestPermittedRequestLevel())
        .thenReturn(ImageRequest.RequestLevel.FULL_FETCH);
    when(mProducerContext.getCallerContext()).thenReturn(PRODUCER_NAME);
    when(mCacheKeyFactory.getBitmapCacheKey(mImageRequest, PRODUCER_NAME)).thenReturn(mCacheKey);
  }
コード例 #5
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);
  }
コード例 #6
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);
 }
コード例 #7
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);
 }