-
Notifications
You must be signed in to change notification settings - Fork 38
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
Cleaner api contracts #40
Labels
enhancement
New feature or request
Comments
maypok86
added a commit
that referenced
this issue
Jan 21, 2024
maypok86
added a commit
that referenced
this issue
Jan 21, 2024
maypok86
added a commit
that referenced
this issue
Jan 21, 2024
maypok86
added a commit
that referenced
this issue
Jan 21, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clarification and motivation
Now otter uses an api very similar to other go cache libraries, but unfortunately it is not particularly beautiful and extensible.
For example, now we have
Set(key, value)
andSetWithTTL(key, value, ttl)
functions, but if we want to addSetIfAbsent(key, value)
function, we also needSetIfAbsentWithTTL(key, value, ttl)
function, which doesn't look nice anymore. Especially since when we create the cache in the builder we already know its further behavior and whether it will need ttl or not.We would like to create a cache with a clean api and with the functions it needs using parameters in the builder. This will allow to provide such api as
Set(key, value, ttl)
andSetIfAbsent(key, value, ttl)
. Also, since in most cases ttl is the same for all entries in the cache, we don't need to pass it every time at all, further simplifying the api. This will also allow us to use optimizations for the expiration policy, since with the same ttl we only need to maintain a simple fifo queue of items and check their expiration one by one.Acceptance criteria
The text was updated successfully, but these errors were encountered: