prom85
prom85

Reputation: 17878

Universal Image Loader - removing single image from cache not working

I calling following code before loading an image:

String url = getUrlImageIcon();
MemoryCacheUtil.removeFromCache(url, ImageLoader.getInstance().getMemoryCache());
DiscCacheUtil.removeFromCache(url, ImageLoader.getInstance().getDiscCache());

ImageLoader.getInstance().displayImage(url, imageView, listener);

My Problem is, this is not deleting the image from cache, the image loader is still displaying the old image afterwards... The old image is not even existing on the server anymore...

How can I remove all cached files from an image correctly?

PS: I'm using the up-to-date version 1.9.1...

Upvotes: 14

Views: 7244

Answers (2)

vanomart
vanomart

Reputation: 1839

According to developer of this library is solution quite simple. All you need to do is to delete cached image from memory and also from disk. How to do that is shown below.

File imageFile = imageLoader.getDiscCache().get(imageUri);
if (imageFile.exists()) {
    imageFile.delete();
}
MemoryCacheUtils.removeFromCache(imageUri, imageLoader.getMemoryCache());

Snippet above is from this issue.

Upvotes: 7

Rohit
Rohit

Reputation: 2568

What @vanomart answered is perfect, just to update the answer. Currently, UIL supports,

MemoryCacheUtils.removeFromCache(imageUri, imageLoader.getMemoryCache());
DiskCacheUtils.removeFromCache(imageUri, imageLoader.getDiskCache());

So, there is better way to clear disk cache.

Upvotes: 15

Related Questions