通用图像加载器 - 无法从缓存中删除单个图像

14

在加载图像之前,我调用了如下代码:

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

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

我的问题是,这并没有从缓存中删除图像,图像加载器仍然显示旧图像...而旧的图像甚至在服务器上不存在...

我该如何正确地删除图像的所有缓存文件?

PS:我正在使用最新版本1.9.1...

2个回答

15

@vanomart所回答的非常完美,只需更新回答。目前,UIL支持:

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

所以,有更好的方法来清除磁盘缓存。


你可能使用了“Disc”而不是“Disk”。 “Disk”并没有被弃用。 - Rohit

7

根据该库的开发者,解决方案非常简单。您只需要从内存和磁盘中删除缓存的图像即可。如何操作如下所示。

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

上面的片段来自于这个问题。

UIL现在有DiskCacheUtils,因此无需手动处理磁盘部分。请查看@rohit的答案。 - Bitcoin Cash - ADA enthusiast

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接