-
-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Is your feature request related to a problem? Please describe.
I want to create a bitmap cache (ie val bitmapCache = InMemoryKache<Int, Bitmap>).
If I run bitmapCache.get(1) I want to get the data. If it doesn't exist, it should automatically run a suspending function first, then return the value.
getOrPut theoretically does this, but I would have to tediously copy over the creationFunction function to all places where I want to get values.
Describe the solution you'd like
The Configuration could accept a factory lambda.
Describe alternatives you've considered
Define a lambda like this once, and reference it in all getOrPut calls:
val bitmapConstruction = { resId: Int ->
bitmapHelper.getBitmap(resId, context)
}
bitmapCache.getOrPut(R.drawable.xyz, bitmapConstruction)
Additional context
LruCache has a way to override the create method to do just this. But it's written in Java and doesn't support coroutines etc.