diff options
| author | 2026-03-06 04:43:03 +0800 | |
|---|---|---|
| committer | 2026-03-06 04:43:03 +0800 | |
| commit | fec8b64975f952e2fa5fa8478b09dced87f0fa7b (patch) | |
| tree | 358cea12d4f20d6821202f040aeb9be58eb878a7 /internal/lru/evict.go | |
| parent | format/commitgraph/bloom: Add commit-graph bloom filters (diff) | |
| signature | No signature | |
internal/lru: Split
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) + } +} |
