Published 22 Oct, 2022

Java - Coil Image Loader : Cache Bitmap with a key

Category Java
Modified : Nov 29, 2022

I am using Coil Image loading library.

My Problem:

I am not getting image Url from backend, rather I am getting JPEG encoded String with its name / key.

What I was wondering is if there is any inbuilt support for caching bitmap with respect to a key so that I can avoid asking for that encoded string every time I want to show that Image.

Is it possible? If not what might be the best way to solve my issue?

Thanks in advance.


There are 1 suggested solutions here and each one has been listed below with a detailed description. The following topics have been covered briefly such as Java, Android, Kotlin, Coil. These have been categorized in sections for a clear and precise explanation.


Coil relies on OkHttp's disk cache which controls its own cache key which is based off the URL. However it's possible to set the memory cache key using RequestBuilder.key.

If you need to set the cache key for the data after it's been fetched, I don't think there's an inbuilt solution for that at the moment unfortunately.