limit

package
v0.31.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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]) IsStale

func (b *Bucket[V]) IsStale() (stale bool)

IsStale returns true if the latest item in the bucket is expired.

func (*Bucket[V]) Upsert

func (b *Bucket[V]) Upsert(value V, priority time.Time) (ok bool)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL