Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket[V comparable] struct { // contains filtered or unexported fields }
Bucket is a simple cache for values with priority(expiry). It has: - configurable capacity. - a mutex for thread safety. - a sorted heap of items for priority/expiry based eviction. - an index of items for fast updates.
func NewBucket ¶
func NewBucket[V comparable](capacity int) *Bucket[V]
NewBucket creates a new bucket with the given capacity. All internal data structures are initialized to the given capacity to avoid allocations during runtime.
func (*Bucket[V]) Upsert ¶
Upsert tries to add a new value and its priority to the bucket. If the value is already in the bucket, its priority is updated. If the bucket is not full, the new value is added. If the bucket is full, oldest expired item is evicted based on priority and the new value is added. Otherwise the new value is ignored and the method returns false.