Universal Image Loader - removing single image from cache not working
Asked Answered
C

2

14

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...

Clovah answered 2/3, 2014 at 10:39 Comment(0)
Q
15

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.

Quan answered 18/8, 2014 at 13:23 Comment(1)
You may have used 'Disc' instead of 'Disk'. 'Disk' is not deprecated.Quan
H
7

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.

Hermaherman answered 27/4, 2014 at 18:51 Comment(1)
UIL now has DiskCacheUtils, so there is no need to do the disk part manually. Check @rohit's answer.Emmalineemmalyn

© 2022 - 2024 — McMap. All rights reserved.