-
Notifications
You must be signed in to change notification settings - Fork 504
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
expirable-lru: cache.Get() not refreshing entry's TTL #186
Comments
What do you expect from this? I see it fails after 100ms, the exp is 100ms actually |
What I'm expecting is: when an item is In my scenario I need a GC like mechanism, a frequently used item will keep alive in cache as long as necessary, and get purged until not in use for a given time. |
This make sense, I have a patch for this and I can open a PR but I found the test @mukeshjc what are your thoughts on this? |
This is a design choice that impacts the semantics and usage of the cache.
This is useful in scenarios where you want cache entries to expire at a predictable time regardless of access patterns. For example, if caching authorization tokens that should expire at a fixed time (and auto-evicted from cache), you wouldn't want reads to extend their lifetime. |
@mukeshjc IMO both scenarios are sensible, how about making it optional? |
There will be deeper changes needed to support that usecase and honestly would be overloading the current implementation with multiple optionalities. The current implementation has a clear, single responsibility. LRU and TTL mechanisms serves a distinct purpose: LRU for space management, TTL for time-based validity. These work independently and predictably Example edge case:
Additionally, the usecase of keeping a value "alive" in cache when |
The behaviour described by @shellohunter is useful in case of you set a key and you don't actually GET for a TTL, so make sense to evict. |
@guerinoni could you share the patch somewhere? I'd like to see if I should stick with this lib in my scenario. |
@shellohunter if you would like i can implement an expire version here https://github.com/guerinoni/sieve |
looks like sieve is not thread safe? which is my another concern. |
@shellohunter it is :) (there is a version single thread, and thread safe) |
I'd like to try it, plz ping me when it's available, and thanks for your sharing! @guerinoni |
@shellohunter try to test this if it feeds your need |
The following test case will fail. Seems there's no way to keep an entry alive.
IMO,
Peek
retrieves data without updating its TTL, butGet
does. So if we keepGet
its value before it expires, wee keep it alive. Am I correct?The text was updated successfully, but these errors were encountered: