coil-kt / coil

Image loading for Android and Compose Multiplatform.
https://coil-kt.github.io/coil/
Apache License 2.0
10.87k stars 669 forks source link

Find cache key with real key #620

Closed ardyfeb closed 3 years ago

ardyfeb commented 3 years ago

How to find MemoryCache.Key with they real key?

On HttpUriFetcher, MemoryCache.Key key is generated based on data.toString() that is image url.

In case i not hold MemoryCache.Key returned from ImageResult how i can find MemoryCache.Key instance by they real key (image url).

Does MemoryCache.get(MemoryCache.Key("some-url)) (construct new memory cache key with same real key) will return cached bitmap from previous cached request that load image with some-url ?

ardyfeb commented 3 years ago

And how get real key as string from MemoryCache.Key instance ?

I currently making Coil bridge for React Native, so is not possible pass java / kotlin class to javascript side

https://github.com/ardyfeb/react-native-coil

colinrtwhite commented 3 years ago

It's not possible to get the URL from a MemoryCache.Key instance. If you need a unique key to pass to Javascript, you could probably use the toString value of the MemoryCache.Key.

ardyfeb commented 3 years ago

@colinrtwhite Thanks, i need to make custom key generator on this case

Back to my first question, does new constructed Key with same real key resolve same cached bitmap?

colinrtwhite commented 3 years ago

No, keys created by the image pipeline are different from simple keys created with a String: https://github.com/coil-kt/coil/blob/master/coil-base/src/main/java/coil/memory/MemoryCache.kt#L63

ardyfeb commented 3 years ago

@colinrtwhite thanks