File tree Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Expand file tree Collapse file tree 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() {
249249 if c .expManager .len () == 0 {
250250 return false
251251 }
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
261256 }
257+ c .expManager .update (key , expiration )
262258 return false
263259 }
264260
Original file line number Diff line number Diff line change @@ -37,11 +37,12 @@ func (m *expirationManager[K]) len() int {
3737 return m .queue .Len ()
3838}
3939
40- func (m * expirationManager [K ]) pop () K {
40+ func (m * expirationManager [K ]) pop () ( K , time. Time ) {
4141 v := heap .Pop (& m .queue )
4242 key := v .(* expirationKey [K ]).key
43+ exp := v .(* expirationKey [K ]).expiration
4344 delete (m .mapping , key )
44- return key
45+ return key , exp
4546}
4647
4748func (m * expirationManager [K ]) remove (key K ) {
You can’t perform that action at this time.
0 commit comments