-
Notifications
You must be signed in to change notification settings - Fork 3
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
Scan method on the LRU to iterate over the keys and values #34
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require.Equal(t, []int{0, 1, 3, 5, 6}, keys) | ||
require.Equal(t, []int{0, 16, 48, 80, 96}, values) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bit shift values on init, but normie numbers on assert? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm full of complexities and contradictions
Also whoa. TIL that Github Markdown supports admonitions??? |
@iuga : You can ignore G115 in |
Overview
Scanning the key values in an LRU cache allows you to efficiently manage, analyze, and manipulate the cached data. By scanning, you can identify which keys are still relevant, which ones can be evicted, and how to optimize cache performance or resource utilization.
Important
As we are utilizing the latest Golang iterators, the minimum required Go version for this package is now
v1.23
.Use Cases
Cache Preloading (Warm-up): In scenarios where anticipated high traffic or load spikes are expected, scanning the cache keys can identify critical data that should be retained or preloaded. This process, known as cache warm-up, ensures that essential data is readily available, reducing latency and improving system performance during peak times.
Usage Analytics and Cache Tuning: Regularly scanning the cache keys provides valuable insights into data access patterns and cache utilization. By analyzing which keys are frequently accessed or close to eviction, it is possible to fine-tune cache parameters, such as size or time-to-live (TTL)
Usage
Scan()
returns an iterator that yields current non-expired items from the cache. It iterates over a snapshot of keys taken at the beginning of iteration, checking each key's existence and expiration before yielding its associated value.Benchmarks
Average times to Scan and extract all the keys from the cache based on 5000 iterations: