Closed MFlisar closed 4 years ago
You can clear the memory cache using imageLoader.memoryCache.clear()
. To clear the disk cache you'll need to get the Cache
used by your ImageLoader
. You can get the default Cache
using CoilUtils.createDefaultCache
. Then call cache.directory().delete()
.
Just if someone else also reads this, we must of course delete the cache directory including it's content, easily done with the deleteRecursively
kotlin extension function on the File
class, e.g. like following:
fun clearCache(context: Context, memory: Boolean = true, file: Boolean= true) {
// 1) clear memory cache
if (memory) {
val imageLoader = context.imageLoader
imageLoader.memoryCache.clear()
}
// 2) clear file cache
if (file) {
val cache = CoilUtils.createDefaultCache(context)
cache.directory().deleteRecursively()
}
}
Just if someone else also reads this, we must of course delete the cache directory including it's content, easily done with the
deleteRecursively
kotlin extension function on theFile
class, e.g. like following:fun clearCache(context: Context, memory: Boolean = true, file: Boolean= true) { // 1) clear memory cache if (memory) { val imageLoader = context.imageLoader imageLoader.memoryCache.clear() } // 2) clear file cache if (file) { val cache = CoilUtils.createDefaultCache(context) cache.directory().deleteRecursively() } }
coil-kt:coil:2.1.0
, The CoilUtils.createDefaultCache()
deprecated.
Coil 2.x has its own disk cache and should not use OkHttp's Cache. https://coil-kt.github.io/coil/image_loaders/
And for coil 2.x delete cache
https://stackoverflow.com/questions/71120310/how-can-i-get-a-new-image-not-cached-in-android-coil
Is this possible? I need this to be done globally. I know I can disable the cache for single requests like following:
But this is not enough for me. I want to delete all cached data from memory and disk and let coil start from a clean new state again.
My use case is that I load icons for apps inside my app and at some point it happens that apps do change their icons. I want to have a function to reset coil completely for such cases.