-
Notifications
You must be signed in to change notification settings - Fork 28
[FSSDK-11158] update: add remove method in LRU Cache for CMAB service #366
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
base: master
Are you sure you want to change the base?
[FSSDK-11158] update: add remove method in LRU Cache for CMAB service #366
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.
Pull Request Overview
This PR adds a remove
method to the LRUCache
class and includes corresponding tests to ensure it works under various conditions.
- Implement
remove
inlib/optimizely/odp/lru_cache.rb
- Add specs covering removal of existing keys, non-existent keys, zero-sized caches, re-adding keys, and thread safety in
spec/odp/lru_cache_spec.rb
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
lib/optimizely/odp/lru_cache.rb | Added remove method to delete cache entries |
spec/odp/lru_cache_spec.rb | New tests for remove behavior under multiple scenarios |
return if @capacity <= 0 | ||
|
||
@cache_mutex.synchronize do | ||
@map.delete(key) |
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 remove
method deletes the entry from the map but does not unlink the corresponding node from the internal doubly linked list, which can lead to stale nodes and incorrect eviction behavior. Consider retrieving the node before deletion and performing proper list unlinking (updating prev
and next
pointers) within the synchronized block.
@map.delete(key) | |
element = @map.delete(key) | |
return nil unless element | |
# Unlink the node from the doubly linked list | |
if element.prev | |
element.prev.next = element.next | |
end | |
if element.next | |
element.next.prev = element.prev | |
end |
Copilot uses AI. Check for mistakes.
end | ||
end | ||
|
||
expect(cache.instance_variable_get('@map').size).to eq(max_size / 2) |
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.
[nitpick] The test inspects the private @map
instance variable directly. It’s more maintainable to expose a public method (e.g., size
or count
) on LRUCache
for checking the number of entries, rather than relying on internal state.
expect(cache.instance_variable_get('@map').size).to eq(max_size / 2) | |
expect(cache.size).to eq(max_size / 2) |
Copilot uses AI. Check for mistakes.
Summary
Added remove method in LRU cache class
Test plan
Added remove method in LRU cache class
Issues
FSSDK-11158