2014-03-02 28 views
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 ...

回答

7

根據這個庫的開發者解決方案相當簡單。您只需從內存和磁盤上刪除緩存的圖像。如何做到這一點如下所示。

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

上面的代碼是從this問題。

+1

* MemoryCacheUtils –

+0

UIL現在擁有DiskCacheUtils,因此不需要手動執行磁盤部分。檢查@ rohit的答案。 – Tiago

15

@vanomart回答的是完美的,只是爲了更新答案。目前,UIL支持,

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

所以,有更好的方法來清除磁盤緩存。

+0

已棄用。 –

+0

您可能使用過「光盤」而不是「磁盤」。 '磁盤'不被棄用。 – rohit

+0

你救我的工作! – yuchaozh