From caea250b3894e456891fca43d1d0d2627d1ffee4 Mon Sep 17 00:00:00 2001 From: Dong Nguyen Date: Sat, 17 Jun 2023 13:46:32 +0700 Subject: [PATCH] call evict on replacing value --- simplelru/lru.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/simplelru/lru.go b/simplelru/lru.go index ac25664..b165ea2 100644 --- a/simplelru/lru.go +++ b/simplelru/lru.go @@ -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 }