Search in sources :

Example 16 with CacheKey

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);
        }
    });
}
Also used : Task(bolts.Task) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) CacheKey(com.facebook.cache.common.CacheKey) CancellationException(java.util.concurrent.CancellationException)

Example 17 with CacheKey

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++;
    }
}
Also used : CloseableImage(com.facebook.imagepipeline.image.CloseableImage) File(java.io.File) CacheKey(com.facebook.cache.common.CacheKey) BitmapMemoryCacheKey(com.facebook.imagepipeline.cache.BitmapMemoryCacheKey) CountingMemoryCacheInspector(com.facebook.imagepipeline.cache.CountingMemoryCacheInspector) CloseableBitmap(com.facebook.imagepipeline.image.CloseableBitmap)

Example 18 with CacheKey

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();
    }
}
Also used : ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CacheKey(com.facebook.cache.common.CacheKey) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource)

Example 19 with CacheKey

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;
}
Also used : CacheKeyFactory(com.facebook.imagepipeline.cache.CacheKeyFactory) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CacheKey(com.facebook.cache.common.CacheKey)

Example 20 with 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));
}
Also used : MemoryCacheParams(com.facebook.imagepipeline.cache.MemoryCacheParams) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) CacheKey(com.facebook.cache.common.CacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) Before(org.junit.Before)

Aggregations

CacheKey (com.facebook.cache.common.CacheKey)49 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)31 MultiCacheKey (com.facebook.cache.common.MultiCacheKey)29 Test (org.junit.Test)22 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)19 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)10 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)8 ArrayList (java.util.ArrayList)8 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)7 BinaryResource (com.facebook.binaryresource.BinaryResource)5 BitmapMemoryCacheKey (com.facebook.imagepipeline.cache.BitmapMemoryCacheKey)5 File (java.io.File)5 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Before (org.junit.Before)4 Uri (android.net.Uri)3 FileBinaryResource (com.facebook.binaryresource.FileBinaryResource)3 WriterCallback (com.facebook.cache.common.WriterCallback)3 CloseableReference (com.facebook.common.references.CloseableReference)3 IOException (java.io.IOException)3