Android图像加载器库,支持ETag,If-Modified-Since

时间:2012-09-27 11:40:49

标签: java android caching if-modified-since http-etag

我已经使用了一段时间Android Http Image Manager,最近我切换到Android Universal Image Loader

我担心他们都不支持验证本地缓存是否是最新的。

我目前正在寻找的是一个Image Loader库,该社区支持和支持通过ETag和/或If-Modified-Since

检查远程更改

1 个答案:

答案 0 :(得分:1)

Github AUIL问题跟踪器回答了问题。谢谢NOSTRA

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()));
    }
}