Fix TLRUCache keeping stale value when overwriting a key with an expired value#400
Fix TLRUCache keeping stale value when overwriting a key with an expired value#400gaoflow wants to merge 1 commit into
Conversation
Assigning an already-expired value (ttu yields a time that is not in the future) to an existing key returned early before storing it, but left the previous entry untouched. As a result the assignment was silently ignored and the cache kept returning the old value, violating the mapping contract that `cache[key] = value` either stores `value` or removes the key. Drop the existing entry in that case so the key is evicted instead of retaining a stale value.
|
Wow, nice catch! Thanks for reporting, and especially for providing a PR including sound regression tests! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #400 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 1084 1089 +5
=========================================
+ Hits 1084 1089 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Assigning an already-expired value to an existing key in a
TLRUCacheis silently swallowed:__setitem__returns early before storing the new value, but it leaves the previous entry in place. The cache then keeps returning the old value, even though the assignment should have replaced (or removed) it.When the new value is dead-on-arrival, drop any existing entry for that key so it is evicted instead of retaining the stale value. New-key inserts of expired values remain a no-op as before. Added a regression test.