4

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

恐怕他们都不支持验证本地缓存是否是最新的。

我目前正在寻找的是一个具有社区支持和支持通过ETag和/或If-Modified-Since检查远程更改的 Image Loader 库

4

1 回答 1

2

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()));
    }
}
于 2013-10-08T07:52:30.900 回答