【发布时间】:2013-05-16 17:53:23
【问题描述】:
我正在尝试为Android Volley Framework 的ImageLoader 功能创建一个简单的演示。构造函数如下:
public ImageLoader(RequestQueue queue, ImageCache imageCache)
问题在于ImageCache。它的 JavaDoc 声明:
简单的缓存适配器接口。如果提供给 ImageLoader,它 在分发到 Volley 之前将用作 L1 缓存。实现 不得阻塞。建议使用 LruCache 实现。
- 在这种情况下,“实施不得阻塞”究竟是什么意思?
- 是否有非阻塞文件缓存(即使是非 android 但“纯”java)的示例,我可以用它来教育我自己如何将现有文件缓存转换为非阻塞?
-
如果不存在 - 使用我现有的实现可能是什么负面影响(只是从文件中读取):
公共字节[] get(字符串文件名) {
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;}
【问题讨论】:
标签: java android android-volley