File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
lib/datadog/appsec/api_security
spec/datadog/appsec/api_security Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ def [](key)
31
31
end
32
32
33
33
def store ( key , value )
34
+ return @store [ key ] = value if @store . delete ( key )
35
+
34
36
# NOTE: evict the oldest entry if store reached the maximum allowed size
35
37
@store . shift if @store . size >= @max_size
36
38
@store [ key ] = value
Original file line number Diff line number Diff line change 58
58
. from ( 'old-value' ) . to ( 'new-value' )
59
59
end
60
60
61
+ context 'when cache is full and an existing key is updated' do
62
+ it 'does not remove other entries' do
63
+ lru_cache . store ( :key2 , 'value2' )
64
+ lru_cache . store ( :key3 , 'value3' )
65
+ lru_cache . store ( :key1 , 'value1' )
66
+
67
+ lru_cache . store ( :key1 , 'new-value1' )
68
+ lru_cache . store ( :key3 , 'new-value3' )
69
+ lru_cache . store ( :key2 , 'new-value2' )
70
+
71
+ aggregate_failures 'verifying LRU cache contents' do
72
+ expect ( lru_cache [ :key1 ] ) . to eq ( 'new-value1' )
73
+ expect ( lru_cache [ :key2 ] ) . to eq ( 'new-value2' )
74
+ expect ( lru_cache [ :key3 ] ) . to eq ( 'new-value3' )
75
+ end
76
+ end
77
+ end
78
+
61
79
context 'when maximum size is reached' do
62
80
it 'evicts the least recently used item' do
63
81
lru_cache . store ( :key1 , 'value1' )
You can’t perform that action at this time.
0 commit comments