可以这样做吗?
我的场景是天气图与URL保持不变,而底层图像实际上是变化的。下面是我想要介绍的案例:-在我的应用程序的同一个会话中(通常是2-5分钟),我从来不想从网络上重新加载图像--大约15分钟后,图像可能已经改变了,因此即使我有缓存的版本,我也想转储它。-当尝试在脱机时重新加载图像时,任何图像(包括旧图像)都比没有图像要好,所以我想从磁盘缓存中显示它。
这是可能的吗?对于UIL来说,它是否可行似乎并不是立即显而易见的。
感谢伟大的图书馆!
发布于 2013-03-25 08:17:21
我认为这是你的解决方案:
File cacheDir = StorageUtils.getCacheDirectory(context); // or any other folder
MemoryCacheAware<String, Bitmap> memoryCacheCore
= new LruMemoryCache(4 * 1024 * 1024); // or any other implementation
MemoryCacheAware<String, Bitmap> memoryCache
= new LimitedAgeMemoryCache<String, Bitmap>(memoryCacheCore, 15 * 60);
DiscCacheAware discCache = new LimitedAgeDiscCache(cacheDir, 15 * 60);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.memoryCache(memoryCache)
.discCache(discCache)
...
.build();UPD: UIL总是首先在内存缓存中搜索所需的图像。然后UIL在磁盘缓存中搜索它。然后从网络下载图像。
如果您使用“有限年龄”内存缓存或磁盘缓存,则位图或图像文件将在超时后从缓存中删除(实际上,它们将在缓存中搜索期间被删除)。逻辑如下:
- bitmap was added to cache recently
- get the bitmap, display it. End.
- no needed bitmap in cache, go to step 2
- image was added to cache recently
- decode image to bitmap, display it. End.
- no needed image in cache, go to step 3
不要忘记启用缓存(在显示选项中,DisplayImageOptions)。
https://stackoverflow.com/questions/15609749
复制相似问题