diff options
Diffstat (limited to 'internal/lru/evict.go')
| -rw-r--r-- | internal/lru/evict.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/lru/evict.go b/internal/lru/evict.go new file mode 100644 index 00000000..9659dd4f --- /dev/null +++ b/internal/lru/evict.go @@ -0,0 +1,17 @@ +package lru + +// OnEvictFunc runs when an entry leaves the cache. +// +// It is called for evictions, explicit removals, Clear, and replacement by Add. +type OnEvictFunc[K comparable, V any] func(key K, value V) + +func (cache *Cache[K, V]) evictOverBudget() { + for cache.weight > cache.maxWeight { + elem := cache.lru.Front() + if elem == nil { + return + } + + cache.removeElem(elem) + } +} |
