Giter Site home page Giter Site logo

Dynamic TTL about cache4k HOT 5 OPEN

caeus avatar caeus commented on September 27, 2024 3
Dynamic TTL

from cache4k.

Comments (5)

glockbender avatar glockbender commented on September 27, 2024

It is such a good and useful enhancement and it would be awesome to have it in this lib.

from cache4k.

Shabinder avatar Shabinder commented on September 27, 2024

we even have kotlinx.datetime which should make this simpler to impl for all platforms in commonMain only.

from cache4k.

ychescale9 avatar ychescale9 commented on September 27, 2024

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.

glockbender avatar glockbender commented on September 27, 2024

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.

caeus avatar caeus commented on September 27, 2024

I'd add the feature as part of the builder:

dynamicExpireAfterWrite{ it.expires_in.seconds }

from cache4k.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.