/** * 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; }
/** Clear disk caches */ public void clearDiskCaches() { mMainBufferedDiskCache.clearAll(); mSmallImageBufferedDiskCache.clearAll(); }
/** * 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); }
/** * 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); }