我已经使用Android Http图像管理器一段时间了,最近我切换到Android Universal Image Loader
恐怕它们都不支持验证本地缓存是否是最新的。
我目前正在寻找的是一个图像加载器库,具有社区支持和支持通过 ETag 和/或 If-Modified-Since 检查远程更改
问题由 Github AUIL 问题跟踪器回答。谢谢诺斯特拉
https://github.com/nostra13/Android-Universal-Image-Loader/issues/75
public class URLConnectionImageDownloader extends ImageDownloader {
@Override
public InputStream getStreamFromNetwork(URI imageUri) throws IOException {
URLConnection conn = imageUri.toURL().openConnection();
// check etag/last-modification-date/... params
// if image was changed then we should delete cached image from memory cache and disc cache
// Delete image from caches
String uri = imageUri.toString();
File imageFile = ImageLoader.getDiscCache().get(uri)
if (imageFile.exists()) {
imageFile.delete();
}
MemoryCacheAware<String, Bitmap memoryCache = ImageLoader.getMemoryCache();
for (String cacheKey : memoryCache.keys()) {
if (cacheKey.contains(uri) {
memoryCache.remove(cacheKey);
}
}
return new FlushedInputStream(new BufferedInputStream(conn.getInputStream()));
}
}