So I'm using Coil image loading library to load images from an API by specifying the image URL. However when there is no internet connection I want to be able to see those images in my app. Is there any support for that kind of thing in Coil library or we should store those images locally by ourselves?
And if so, should we convert that image URL to bitmap using Coil and then save it locally?
UPDATE:
I'm using the library with Jetpack Compose btw.
val painter = rememberImagePainter("$BASE_URL${item.image}") {
memoryCachePolicy(policy = CachePolicy.ENABLED)
}
Coil does cache the images on the disk of the device to be able to use them offline but only when the response header of the image request includes cache control headers that allow Coil to do that. The reason for that is that Coil uses disk cache provided by OkHttp and not an own cache implementation. UPDATE: Coil 2.x uses an own cache implementation now but that hasn't affected this solution.
Check the response header of the image request and look for headers like Cache-Control: no-cache, no-store, max-age=0, must-revalidate, ... and/or Pragma: no-cache (For all cache control headers see: Cache-Control MDN Web docs)
If one these is present OkHttp will not store the response on the disk cache. You can solve this by changing the api configuration to allow caching of images (if you have access to that) or providing a OkHttp interceptor that changes the response header. See: Interceptors: Rewriting Responses