Kamel-Media / Kamel

Kotlin asynchronous media loading and caching library for Compose.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provide custom cache key

garretyoder opened this issue · comments

I was reading through the code but didn't see an example, is it possible to provide a custom key value for the cache to Kamel? If not, can this be a feature request?

In my use case I'm looking to be able to feed it a http url for something that isn't an image and if that url key exists in cache, then load it, if not then I will provide a method that takes that url and returns a url to an actual image for it to go load - but then it needs to be cached under the other URL.

Is it possible to give Kamel a custom cache k/v pair class where I could implement this and get some kind of onNotInCache method where I can return the real img url?

I think you can make your own mapper to do that, if I understand correctly.

I'm looking at https://github.com/Kamel-Media/Kamel/blob/main/kamel-core/src/commonJvmMain/kotlin/io/kamel/core/mapper/JvmMappers.kt as an example and that just looks like the translation of the URL, but no ability to do some background processing when the image does not yet exist in cache unless I'm misunderstanding how it works.

I'm building some website image previews, so I'm looking to be able to feed it a base url (eg; github.com) and if that key exists in cache already, then it will pull the cached image. If not, then I can get a callback of some sort where I can go parse that website to pull out the image I want such as og:image or something similar, and then download that image but cache it under the original base url so I only have to parse website html once.