-
Notifications
You must be signed in to change notification settings - Fork 28
feat: add lru cache #306
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
feat: add lru cache #306
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.
Looks great. A fix suggested.
return nil if old_element.stale?(@timeout) | ||
|
||
element = CacheElement.new(old_element.value) | ||
@map[key] = element |
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.
It looks like ruby hash keeps insertion order for 1.9+. Min ruby version we support?
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.
That's one of the main reasons I pushed for updating the minimum supported ruby version. As of 4.0.0, we now only support >=2.7
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.
@andrewleap-optimizely That min version info should be in README.md file and our docs. Updated?
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.
The minimum version is listed on the rubygems page but yea we should add it to the readme as well. Looks like a lot of the sdks are missing that information on their readme/docs, may be worth discussing.
lib/optimizely/odp/lru_cache.rb
Outdated
@map.delete(key) | ||
return nil if old_element.stale?(@timeout) | ||
|
||
element = CacheElement.new(old_element.value) |
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.
Timestamp is not supposed to change for lookup. This new creation will overwrite the old timestamp.
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.
good catch. Fixed and added test to confirm.
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.
LGTM
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.
Looks Great!
Summary
Add a generic LRU cache to support efficient caching of the ODP segments results.
Test plan
Added:
Ticket:
OASIS-8435