Cancelled postprocessed images aren't cached
See original GitHub issueHi guys,
First of all, great library! Only problem I’ve had so far is with caching of post processed images - I’m following the documentation put up, and have looked around, but can’t seem to figure out what’s going wrong here.
I have a FragmentStatePagerAdapter, with each fragment having a full-sized, blurred image as its background, and I have a post-processor that blurs the background image, and all of that is working fine. But when I scroll between the fragments back and forth, the blurred background image is reprocessed every time, which is really annoying. There’s a section in the docs saying that post-processed images can be cached, and I’m doing everything it’s saying I should, but images are still not being caches.
My post-processor:
public class BlurPostprocessor extends BasePostprocessor {
private Context context;
private String url;
public BlurPostprocessor(Context context, String url) {
this.context = context;
this.url = url;
}
@Override
public String getName() {
return "blurPostProcessor";
}
@Override
public CacheKey getPostprocessorCacheKey() {
return new SimpleCacheKey(url);
}
@Override
public void process(Bitmap destBitmap, Bitmap sourceBitmap) {
// code that blurs the image into destBitmap
}
}
I’ve also tried implementing my own CacheKey before finding out about SimpleCacheKey, but that didn’t work either. Any help would be appreciated!
Thanks!
Issue Analytics
- State:
- Created 8 years ago
- Comments:23 (7 by maintainers)
Top GitHub Comments
There’s no straightforward solution to this, but we’ve discussed internally and would like to provide some suggestions.
First, have a look at our sample
ScalingBlurPostprocessor
. This is much, much faster than the normal blur processor and produces almost indistinguishable results.Second, in your custom post processor, you can evict the original image from memory cache. This will help keep more blurred images in the cache. Simply call
imagePipeline.evictFromMemoryCache(uri)
in yourprocess()
method.Third, if you want to get fancy and cache the blurred image to disk cache, you can write a custom decoder (there are examples in the repo) that does the blurring implicitly. This will cause the original image to be thrown away and only the blurred one to be cached in both memory and disk caches.
I’ll close this now as it’s unlikely that we’ll make any changes within the library to address it.
CC @oprisnik
I am also experiencing the same problem!