hot icon indicating copy to clipboard operation
hot copied to clipboard

Unbounded cache (infinite capacity)

Open rytsh opened this issue 3 months ago • 4 comments

// NewLRUCacheWithEvictionCallback creates a new LRU cache with the specified capacity and eviction callback.
// The callback will be called whenever an item is evicted from the cache.
func NewLRUCacheWithEvictionCallback[K comparable, V any](capacity int, onEviction base.EvictionCallback[K, V]) *LRUCache[K, V] {
	if capacity <= 0 {
		panic("capacity must be greater than 0")
	}

LRUCache accept capacity 0 but this checks blocking it, can we close this one?

[EDITED] I edit previous message because not show correct part

rytsh avatar Sep 11 '25 11:09 rytsh

what is the point of having LRU cache with 0 capacity ?

samber avatar Sep 12 '25 00:09 samber

Right, I just don't want to implement if capacity 0.

Is it possible than add an algorithm without doing eviction but still support TTL or not?

rytsh avatar Sep 12 '25 09:09 rytsh

Hey @rytsh

Can you create a new Unbounded cache strategy ?

I think a b-tree or binary search tree should work fast. (or any O=log n algo)

samber avatar Sep 15 '25 13:09 samber

Yes, I will be prepare something

rytsh avatar Sep 15 '25 13:09 rytsh