candlefinance / faster-image

Fast image loading for React Native backed by performant native libraries.
https://candle.fi/discord
MIT License
479 stars 21 forks source link

Clear cache #32

Closed kierancrown closed 1 month ago

kierancrown commented 1 month ago

Is there a way to clear cache, or plans to implement this feature? This would be useful for testing/debug.

I think in Nuke for iOS it'll look something like this

Nuke.Cache.shared.removeAll()
Nuke.DataLoader.sharedUrlCache.removeAllCachedResponses()

and Coil for Android looking like this

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()
    }
}

I can maybe take a look and open a PR sometime this week, unless someone beats me to it 😁

kierancrown commented 1 month ago

I've opened a PR here for iOS. I'm not as familiar with Kotlin/Android native modules just yet so I'll take a look at that next