我正在嘗試爲Android Volley Framework的ImageLoader功能創建一個簡單演示。構造函數如下:非阻塞文件緩存(BitmapLruCache)的實現?
public ImageLoader(RequestQueue queue, ImageCache imageCache)
問題出在ImageCache
。它的JavaDoc狀態:
簡單緩存適配器接口。如果提供給ImageLoader,它將在發送到Volley之前用作L1緩存。實現 不得阻塞。推薦使用LruCache實施。
- 究竟是什麼「實現必須不能阻止」在這種情況下意味着什麼?
- 有無阻塞文件緩存(甚至非Android,但「純」 JAVA),我可以用它來教育我自己如何轉換我現有的文件緩存是不可阻擋的例子嗎?
如果沒有這樣的存在 - 什麼可能是利用我現有的實施是(只是從文件中讀取)的負面影響:
公共字節[]得到(字符串文件名){
byte[] ret = null; if (filesCache.containsKey(filename)) { FileInfo fi = filesCache.get(filename); BufferedInputStream input; String path = cacheDir + "/" + fi.getStorageFilename(); try { File file = new File(path); if (file.exists()) { input = new BufferedInputStream(new FileInputStream(file)); ret = IOUtils.toByteArray(input); input.close(); } else { KhandroidLog.e("Cannot find file " + path); } } catch (FileNotFoundException e) { filesCache.remove(filename); KhandroidLog.e("Cannot find file: " + path); } catch (IOException e) { KhandroidLog.e(e.getMessage()); } } return ret;
}