File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -177,7 +177,11 @@ def remove_by
177
177
178
178
# Remove keys that are expired.
179
179
def clean
180
- synchronized { @hash . delete_if { |_key , value | expired? ( value ) } }
180
+ synchronized { @hash . delete_if { |key , _value | expired? ( key ) } }
181
+ end
182
+
183
+ def empty?
184
+ @hash . empty?
181
185
end
182
186
183
187
private
Original file line number Diff line number Diff line change @@ -134,6 +134,14 @@ def test_clean
134
134
assert ( cache . exists? ( :bye ) == false )
135
135
end
136
136
137
+ def test_clean_size
138
+ cache = Zache . new
139
+ cache . get ( :hey , lifetime : 0.01 ) { Random . rand }
140
+ sleep 0.1
141
+ cache . clean
142
+ assert ( cache . empty? )
143
+ end
144
+
137
145
def test_clean_with_sync_false
138
146
cache = Zache . new ( sync : false )
139
147
cache . get ( :hey ) { Random . rand }
You can’t perform that action at this time.
0 commit comments