Android Image invalidate in fresco

三世轮回 提交于 2020-01-14 04:49:28

问题


I am migrating android image caching library from picasso to fresco. I want to know if there is any way to invalidate image already catched as I am adding feature to replace existing image there is way to do so in picasso like

Picasso.with(context).invalidate(URI);

This line remove the cached image and use new one using the url provided which is same like,

http://example.com/image_path

In fresco I have tried using

Fresco.getImagePipeline().evictFromMemoryCache(uri);

This is removing image from view but adding same old cached image again and not getting new one from network as it is working in picasso.


Please refer question Invalidate cache in Picasso The accepted answer doing great in case of picasso.


回答1:


Fresco.getImagePipeline().evictFromMemoryCache(uri);

Above code line remove the image from the catche but image remains there in the disk and render same if called. We need to remove same image from disk as well. Bellow two lines remove the the image from disc cache also we need to remove the small that is thumbnail image if saved from disk cache.

Fresco.getImagePipelineFactory().getMainDiskStorageCache().remove(new SimpleCacheKey(uri.toString()));
Fresco.getImagePipelineFactory().getSmallImageDiskStorageCache().remove(new SimpleCacheKey(uri.toString()));

Note: if you are using custom cache key you need to change it that way.




回答2:


Try this

public static void clearCache(){
            //
            ImagePipeline imagePipeline = com.facebook.drawee.backends.pipeline.Fresco.getImagePipeline();
            imagePipeline.clearMemoryCaches();
            imagePipeline.clearDiskCaches();
            // combines above two lines
            imagePipeline.clearCaches();
        }


来源:https://stackoverflow.com/questions/30254189/android-image-invalidate-in-fresco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!