-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic TTL #18
Comments
It is such a good and useful enhancement and it would be awesome to have it in this lib. |
we even have |
Thanks everyone, I might take a look at this soon. Can you share a few examples of your use cases and how you think the APIs should look like? Is this a feature you've used in other caching libraries in the past? |
Example of function description: public data class LoaderContext internal constructor(
var expireAfterAccessDuration: Duration,
var expireAfterWriteDuration: Duration
)
public suspend fun get(key: Key, loader: suspend LoaderContext.() -> Value): Value
// looks like it should be a new 'put' function with 'customizing'
public suspend fun put(key: Key, loader: suspend LoaderContext.() -> Value) Example of usage: suspend fun cacheToken(key: String, ttl: Duration): Any {
cache.put(key) {
// by default cache-level configured values are set
this.expireAfterAccessDuration = ttl
// ...
}
}
suspend fun someFun(key: String, ttl: Duration): Any {
cache.get(key) {
this.expireAfterWriteDuration = ttl
// ...
}
}
Using it a lot with Redis |
I'd add the feature as part of the builder:
|
Is it possible to set the expiration time during execution of the loader?
Trying to cache some oauth tokens whose expiration time is known when the loader gets them. Not before.
The text was updated successfully, but these errors were encountered: