Skip to content

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

Merged
merged 6 commits into from
Aug 9, 2022
Merged

feat: add lru cache #306

merged 6 commits into from
Aug 9, 2022

Conversation

andrewleap-optimizely
Copy link
Contributor

Summary

Add a generic LRU cache to support efficient caching of the ODP segments results.

  • Add Least Recently Used (LRU) cache
  • design to allow developer to pass in different caching implementation. Provide default.

Test plan

Added:

  • lru_cache_spec.rb

Ticket:

OASIS-8435

@andrewleap-optimizely andrewleap-optimizely marked this pull request as ready for review August 8, 2022 14:28
@andrewleap-optimizely andrewleap-optimizely requested a review from a team as a code owner August 8, 2022 14:28
Copy link
Contributor

@jaeopt jaeopt left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@map.delete(key)
return nil if old_element.stale?(@timeout)

element = CacheElement.new(old_element.value)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Great!

@andrewleap-optimizely andrewleap-optimizely merged commit 6c12bfd into master Aug 9, 2022
@andrewleap-optimizely andrewleap-optimizely deleted the aleap/add_lru_cache branch August 9, 2022 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants