From fec8b64975f952e2fa5fa8478b09dced87f0fa7b Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 6 Mar 2026 04:43:03 +0800 Subject: internal/lru: Split --- internal/lru/evict.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 internal/lru/evict.go (limited to 'internal/lru/evict.go') 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) + } +} -- cgit v1.3.1-10-gc9f91