Skip to content

Commit

Permalink
freelru: try fix PurgeExpired
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Dec 3, 2024
1 parent 9f69e7f commit ff4ad0c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions contrab/freelru/lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,20 +687,19 @@ func (lru *LRU[K, V]) Purge() {
// PurgeExpired purges all expired items from the LRU.
// The evict function is called for each expired item.
func (lru *LRU[K, V]) PurgeExpired() {
n := now()
loop:
l := lru.len
if l == 0 {
return
}
n := now()
pos := lru.head
for i := uint32(0); i < l; i++ {
next := lru.elements[pos].next
if lru.elements[pos].expire != 0 {
if lru.elements[pos].expire <= n {
lru.removeAt(pos)
}
if lru.elements[pos].expire != 0 && lru.elements[pos].expire <= n {
lru.removeAt(pos)
goto loop
}
pos = next
pos = lru.elements[pos].next
}
}

Expand Down

0 comments on commit ff4ad0c

Please sign in to comment.