androidimage-cachingcoil

Coil image caching


I load my images into an android app with the Coil library. And it instantly shows me cached images if there is no internet. But when there is an internet connection, the Coil loads images again, and for a while I see the placeholder. I think it's a very strange logic. How can I make it show me the cached images instantly even if there is an internet connection?

My current code:

fun ImageView.setPhoto(photoLink: String) {
    load(photoLink) {
        crossfade(true)
        placeholder(R.drawable.placeholder)
        error(R.drawable.placeholder)
        size(ViewSizeResolver(this@setPhoto))
    }
}

Solution

  • Try disabling the cache headers support.

    val imageLoader = ImageLoader.Builder(context)
            .respectCacheHeaders(false)
            .build()
    Coil.setImageLoader(imageLoader)