use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class SplitCachesByImageSizeDiskCachePolicy method createAndStartCacheReadTask.
@Override
public Task<EncodedImage> createAndStartCacheReadTask(ImageRequest imageRequest, Object callerContext, final AtomicBoolean isCancelled) {
final CacheKey cacheKey = mCacheKeyFactory.getEncodedCacheKey(imageRequest, callerContext);
final boolean alreadyInSmall = mSmallImageBufferedDiskCache.containsSync(cacheKey);
final boolean alreadyInMain = mDefaultBufferedDiskCache.containsSync(cacheKey);
final BufferedDiskCache firstCache;
final BufferedDiskCache secondCache;
if (alreadyInSmall || !alreadyInMain) {
firstCache = mSmallImageBufferedDiskCache;
secondCache = mDefaultBufferedDiskCache;
} else {
firstCache = mDefaultBufferedDiskCache;
secondCache = mSmallImageBufferedDiskCache;
}
return firstCache.get(cacheKey, isCancelled).continueWithTask(new Continuation<EncodedImage, Task<EncodedImage>>() {
@Override
public Task<EncodedImage> then(Task<EncodedImage> task) throws Exception {
if (isTaskCancelled(task) || (!task.isFaulted() && task.getResult() != null)) {
return task;
}
return secondCache.get(cacheKey, isCancelled);
}
});
}
use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class BaseFrescoStethoPlugin method storeEntries.
private void storeEntries(List<CountingMemoryCacheInspector.DumpInfoEntry<CacheKey, CloseableImage>> entries, int i, PrintStream writer, File directory) throws IOException {
String filename;
for (CountingMemoryCacheInspector.DumpInfoEntry<CacheKey, CloseableImage> entry : entries) {
CloseableImage closeableImage = entry.value.get();
if (closeableImage instanceof CloseableBitmap) {
CloseableBitmap closeableBitmap = (CloseableBitmap) closeableImage;
filename = "tmp" + i + ".png";
writer.println(formatStrLocaleSafe("Storing image %d as %s. Key: %s", i, filename, entry.key));
storeImage(closeableBitmap.getUnderlyingBitmap(), new File(directory, filename), Bitmap.CompressFormat.PNG, 100);
} else {
writer.println(formatStrLocaleSafe("Image %d has unrecognized type %s. Key: %s", i, closeableImage, entry.key));
}
i++;
}
}
use of com.facebook.cache.common.CacheKey in project ride-read-android by Ride-Read.
the class ImgLoader method getDiscCacheFile.
public File getDiscCacheFile(String url) {
ImageRequest imageRequest = ImageRequest.fromUri(Uri.parse(url));
CacheKey cacheKey = Utils.getAppContext().getImagePipeLineConfig().getCacheKeyFactory().getEncodedCacheKey(imageRequest, null);
FileBinaryResource fileBinaryResource = (FileBinaryResource) Fresco.getImagePipelineFactory().getMainDiskStorageCache().getResource(cacheKey);
if (fileBinaryResource == null) {
return null;
} else {
return fileBinaryResource.getFile();
}
}
use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class PipelineDraweeControllerBuilder method getCacheKey.
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;
}
use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class AnimatedFrameCacheTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MemoryCacheParams params = new MemoryCacheParams(4 * ByteConstants.MB, 256, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
when(mMemoryCacheParamsSupplier.get()).thenReturn(params);
CountingMemoryCache<CacheKey, CloseableImage> countingMemoryCache = BitmapCountingMemoryCacheFactory.get(mMemoryCacheParamsSupplier, mMemoryTrimmableRegistry, mPlatformBitmapFactory, true);
mCacheKey = new SimpleCacheKey("key");
mAnimatedFrameCache = new AnimatedFrameCache(mCacheKey, countingMemoryCache);
mFrame1 = CloseableReference.of(mock(CloseableImage.class));
mFrame2 = CloseableReference.of(mock(CloseableImage.class));
}
Aggregations