Skip to content

Commit

Permalink
call evict on replacing value (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
dongnguyenvt authored Jun 21, 2023
1 parent e456a3e commit d260bc0
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions simplelru/lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func (c *LRU[K, V]) Add(key K, value V) (evicted bool) {
// Check for existing item
if ent, ok := c.items[key]; ok {
c.evictList.moveToFront(ent)
if c.onEvict != nil {
c.onEvict(key, ent.value)
}
ent.value = value
return false
}
Expand Down

0 comments on commit d260bc0

Please sign in to comment.