I am using Coil with Jetpack compose. I noticed that in my LazyColumn items the images that load using coil(downloaded from the network) load faster when the device is offline ( this is once the images are cached of course ).
When the device is online, it seems coil is fetching the network copy even though a local cached version of that image exists.
I would like coil to prioritize fetching images based on the following order:
- Check if it exists in Memory Cache
- If not check if a Disk Cache exists
- If the above 2 don't exist then fetch from the network
How do I achieve this? My current ImageRequest Builder looks like this:
ImageRequest.Builder(LocalContext.current)
.data(downloadUrl)
.crossfade(true)
.crossfade(coilFadeDuration)
.error(R.drawable.black_color_rectangle)
.placeholder(R.drawable.placholder)
.fallback(R.drawable.black_color_rectangle)
.networkCachePolicy(CachePolicy.ENABLED)
.diskCachePolicy(CachePolicy.ENABLED)
.memoryCachePolicy(CachePolicy.ENABLED)
.diskCacheKey(downloadUrl)
.memoryCacheKey(downloadUrl)
.diskCacheKey(downloadUrl)
.memoryCacheKey(downloadUrl)
.size(Size.ORIGINAL)
.build()