I’m currently using Coil in my project with image ...
# multiplatform
s
I’m currently using Coil in my project with image caching and would like to remove a specific image from the cache by URL for example. I’m currently building a singleton
ImageLoader
like this:
Copy code
setSingletonImageLoaderFactory { context ->
        ImageLoader.Builder(context)
            .diskCachePolicy(CachePolicy.ENABLED)
            .networkCachePolicy(CachePolicy.ENABLED)
            .diskCache {
                DiskCache.Builder().directory(FileSystem.SYSTEM_TEMPORARY_DIRECTORY/"coil_img_cache")
                    .maxSizeBytes(256L * 1024 * 1024) /// 256MB
                        .build()
            }
            .crossfade(true)
            .build()
    }
But when I retrieve the singleton using
SingletonImageLoader.get(LocalPlatformContext.current)
, and even forcibly clear out all caches:
Copy code
imgLoader.diskCache?.clear()
imgLoader.memoryCache?.clear()
The image still stays in memory until I clear the cache in the app-options on Android. Does anyone have a better idea on how to approach this? Thanks!
c
Hmm I’d expect the disk cache + memory cache
clear()
code you posted to clean both caches as expected. Maybe you’re somehow referencing different
ImageLoader
instances? You can check the
imageLoader.toString()
on the instance you set + the instance you got to verify
s
I would also expect it to be the same Singleton created inside the factory but I'll take a look, thanks!