Skip to content
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

Closed
maypok86 opened this issue Jan 21, 2024 · 0 comments · Fixed by #41
Closed

Cleaner api contracts #40

maypok86 opened this issue Jan 21, 2024 · 0 comments · Fixed by #41
Labels
enhancement New feature or request

Comments

@maypok86
Copy link
Owner

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) and SetWithTTL(key, value, ttl) functions, but if we want to add SetIfAbsent(key, value) function, we also need SetIfAbsentWithTTL(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) and SetIfAbsent(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

  1. A more advanced version of the builder has been implemented
  2. Otter provides simpler api contracts
  3. Implementation tests are written
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant