Comments (5)
It is such a good and useful enhancement and it would be awesome to have it in this lib.
from cache4k.
we even have kotlinx.datetime
which should make this simpler to impl for all platforms in commonMain only.
from cache4k.
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?
from cache4k.
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
// ...
}
}
Is this a feature you've used in other caching libraries in the past?
Using it a lot with Redis
from cache4k.
I'd add the feature as part of the builder:
dynamicExpireAfterWrite{ it.expires_in.seconds }
from cache4k.
Related Issues (19)
- [Feature] Support listening to cache expiry
- Support for `tvos targets` HOT 6
- Cache is not synchronised by key HOT 8
- KMM New Memory Model HOT 3
- The instance of the TimeMark interface has been changed in Kotlin 1.7.0-Beta HOT 5
- Caching get clear after exit app HOT 1
- Please, add support for linuxX64 HOT 2
- ConcurrentModificationException will be reported when concurrent HOT 9
- `Cache.asMap`'s `Key` is marked as `in`
- 0.9.0 introduces massive performance issues HOT 6
- Publication of FakeTimeSource HOT 2
- Duplicate class error since 0.10.0 (Stately) HOT 6
- Support for null values and loader in the constructor
- value is always returning null HOT 1
- Same key Expiring twice
- Fix linearizability issues surfaced by Lincheck
- Crash at Runtime Startup HOT 7
- Non-daemon thread? [JVM] HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cache4k.