Giter Site home page Giter Site logo

Expiration by time about gokv HOT 2 OPEN

tdakkota avatar tdakkota commented on June 1, 2024
Expiration by time

from gokv.

Comments (2)

tdakkota avatar tdakkota commented on June 1, 2024

I saw the first item of Design decisions, but i think that gokv can provide multiple interfaces, like gokv.Cache

from gokv.

philippgille avatar philippgille commented on June 1, 2024

Hi @tdakkota, thanks for the feature request!

You're right that another interface could be added to the root gokv package and that wouldn't have any negative consequences to packages using gokv.Store so far (like added dependencies or so).

Regarding the implementations it's a little bit more difficult: Redis and Memcached have native support for key-value pair expiration, but other products that have implementations for gokv.Store already don't have this.

There are some ways to implement that on your own:

  • Each xyz.Set("key", "val", expiration) call could lead to a goroutine with a timer that calls xyz.Delete("key") after the expiration, but that wouldn't work as soon as the program crashes or something
  • When xyz.Set is called, it could add its own metadata in addition to the value, with the metadata including the expiration date. A xyz.Get call would lead to gokv checking the expiration in the metadata, deleting the value if the expiration is reached, or otherwise return the actual value. This would lead to the package behaving like a cache, but the cache might actually grow very big due to stale entries that are just not deleted because no xyz.Get was called on them yet.
    • This could be mitigated by a goroutine that runs in the background every now and then to go through all key-value pairs, check their expiration and remove the expired ones. This requires a way to retrieve all key-value pairs though and I'm not sure if all products that have implementations for gokv.Store support this. (It's the same issue for #9).
  • Maybe other ways?

An alternative would be to only support the products that contain an expiration mechanism on their own, like Redis and Memcached. That might lead to confusion by people who use gokv.Store and think something like "when I use this gokv interface I know my package users who use product xyz can use it" and presume the same goes for the cache interface. Although maybe this could be mitigated with good documentation. For example the README could contain a table (instead of the current Implementations list) with the interfaces as columns and the products as rows, like:

Package gokv.Store gokv.Cache
redis ✔️ ✔️
file ✔️

Which would you prefer? (Only support the products with expiration support vs. implementing cache entry deletion on our own for products without expiration support)

from gokv.

Related Issues (20)

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.