File tree 2 files changed +8
-11
lines changed
2 files changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -249,16 +249,12 @@ func (c *Cache[K, V]) DeleteExpired() {
249
249
if c .expManager .len () == 0 {
250
250
return false
251
251
}
252
- key := c .expManager .pop ()
253
- // if is expired, delete it and return nil instead
254
- item , ok := c .cache .Get (key )
255
- if ok {
256
- if item .Expired () {
257
- c .cache .Delete (key )
258
- return true
259
- }
260
- c .expManager .update (key , item .Expiration )
252
+ key , expiration := c .expManager .pop ()
253
+ if nowFunc ().After (expiration ) {
254
+ c .cache .Delete (key )
255
+ return true
261
256
}
257
+ c .expManager .update (key , expiration )
262
258
return false
263
259
}
264
260
Original file line number Diff line number Diff line change @@ -37,11 +37,12 @@ func (m *expirationManager[K]) len() int {
37
37
return m .queue .Len ()
38
38
}
39
39
40
- func (m * expirationManager [K ]) pop () K {
40
+ func (m * expirationManager [K ]) pop () ( K , time. Time ) {
41
41
v := heap .Pop (& m .queue )
42
42
key := v .(* expirationKey [K ]).key
43
+ exp := v .(* expirationKey [K ]).expiration
43
44
delete (m .mapping , key )
44
- return key
45
+ return key , exp
45
46
}
46
47
47
48
func (m * expirationManager [K ]) remove (key K ) {
You can’t perform that action at this time.
0 commit comments