Comments (2)
I saw the first item of Design decisions, but i think that gokv can provide multiple interfaces, like gokv.Cache
from gokv.
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 callsxyz.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. Axyz.Get
call would lead togokv
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 noxyz.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).
- 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
- 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)
- Is this project active? HOT 23
- can support `incr` 、`decr` and `keys` HOT 1
- Expose more features in the Hazelcast client
- S3: don't require attempt to create bucket in s3.NewClient
- encoding: add support for PB (Protocol Buffers)
- redis: add opentelemtry.io instrumentation HOT 1
- redis: update to v9
- ci: add windows and macos HOT 2
- Connection string for all storage HOT 1
- check if the context was already canceled
- Add `timeout` to all store configs and use it in Context
- Add `GetClient` method to all implementations
- Add implementation for Pudge HOT 2
- Add gokv.Store implementation for BuntDB HOT 1
- Support Go modules
- Add more gokv.Store implementations HOT 5
- The BigCache concurrency test is flaky
- Batch operations HOT 3
- Sync() for persistent KV stores.
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 gokv.