So in the end I used an ImageLoadingListener as follows:
onLoadingStarted:
Check for cache when loading starts.
onLoadingComplete:
If no cache was found then do nothing. The request will be sent to network and cache will be updated naturally.
Otherwise clear cache and call displayImage again (no listener needed this time). The cached image will be shown in the view normally. Moreover, when the 2nd loading finishes, view and cache will be updated.
ImageLoader.getInstance().displayImage(imageUri, view, new SimpleImageLoadingListener() {
boolean cacheFound;
@Override
public void onLoadingStarted(String url, View view) {
List<String> memCache = MemoryCacheUtils.findCacheKeysForImageUri(url, ImageLoader.getInstance().getMemoryCache());
cacheFound = !memCache.isEmpty();
if (!cacheFound) {
File discCache = DiscCacheUtils.findInCache(url, ImageLoader.getInstance().getDiscCache());
if (discCache != null) {
cacheFound = discCache.exists();
}
}
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (cacheFound) {
MemoryCacheUtils.removeFromCache(imageUri, ImageLoader.getInstance().getMemoryCache());
DiscCacheUtils.removeFromCache(imageUri, ImageLoader.getInstance().getDiscCache());
ImageLoader.getInstance().displayImage(imageUri, (ImageView) view);
}
}
});
}