I think this is solution for you:
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 always search needed image in memory cache at first. Then UIL search it in disc cache. And then it downloads image from network.
If you use "limited age" memory cache or disc cache then bitmap or image file will be deleted from cache after timeout (actually they will be deleted during search in cache).
Logic is following:
- Search bitmap in memory cache
- needed bitmap is there
- bitmap was added to cache more than specified time ago
- delete it from memory cache, go to step 2
- bitmap was added to cache recently
- get the bitmap, display it. End.
- no needed bitmap in cache, go to step 2
- Search image file in disc cache
- needed image is there
- image was added to cache more than specified time ago
- delete it from disc cache, go to step 3
- image was added to cache recently
- decode image to bitmap, display it. End.
- no needed image in cache, go to step 3
- Download image
Don't forget enable caching (in display options, DisplayImageOptions
).