0
根據我的理解,我們需要提供LRU cache
的實現,並將相同的構造函數傳遞給圖像加載器。在android-volley中如何實現圖像緩存?
volley
中還有一個基於磁盤的默認緩存。這個基於磁盤的緩存用於緩存HTTP
響應。
**當下載的映像包含緩存頭時,將使用哪個緩存?
- LRU(自己的實現)
- 默認磁盤緩存實現本內凌空工具箱包* 強大的文本 * **到 公共類BitmapLruCache擴展LruCache實現ImageLoader.ImageCache
{
public static int getDefaultLruCacheSize() {
final int maxMemory = (int) (Runtime.getRuntime().maxMemory()/1024);
final int cacheSize = maxMemory/8;
return cacheSize;
}
public BitmapLruCache() {
this(getDefaultLruCacheSize());
}
public BitmapLruCache(int sizeInKiloBytes) {
super(sizeInKiloBytes);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight()/1024;
}
@Override
public Bitmap getBitmap(String url) {
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}}
這是用來在n中設置圖像的調用網絡視圖
ImageLoader mImageLoader = new ImageLoader(ApplicationController.getInstance().getRequestQueue(), new BitmapLruCache());
holder.imageicon.setImageUrl(i.getThumb_image(), mImageLoader);
我得到那部分..當圖片url包含緩存標題時將使用哪個緩存? – user2391218
如果你看看我鏈接的源代碼 - 你會發現ImageCache是從ImageLoader類中使用的 - 正如我已經說過的那樣,是你的LruCache的實現。如果您的LruCache存在缺失,HTTP請求將按預期結束,然後它將檢查HTTP緩存,然後如果錯過那裏,請訪問網絡。 – Submersed
好的,謝謝你得到它......但在我的情況下,我的LRU緩存中沒有緩存命中......所有圖像都從基於光盤的緩存中顯示出來......當它發生時,你有什麼想法嗎?已編輯我的文章,以包含LRU實現的源代碼 – user2391218