bounded

package
v1.15.0 Latest Latest
Warning

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

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

Documentation

Overview

Package bounded provides a size-bounded, TTL-aware key→value map for the gateway's per-instance affinity records and its in-process shared-state store.

The stores built on it are all keyed by identifiers the gateway does not choose and cannot bound — upstream resource URIs, upstream-minted task ids, verified principal identities — so an ordinary map is a slow leak a busy federation drives on its own. Eviction is safe at every call site: each falls back to a path that already handles an unknown key (a resource or task probe, a freshly built limiter).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[V any] struct {
	// contains filtered or unexported fields
}

Map is a bounded key→value map with per-entry expiry.

The bound is generational rather than LRU: when the live generation fills, it becomes the previous generation and a fresh one starts. Reads check both and promote what they find, so a key in use survives a rotation and only keys untouched for a full generation are dropped. Every operation is O(1) with no ordering bookkeeping, at a resident cost of at most 2×max entries.

func New

func New[V any](limit int) *Map[V]

New returns an empty map holding at most limit entries per generation.

func (*Map[V]) Delete

func (m *Map[V]) Delete(key string)

Delete removes key from both generations.

func (*Map[V]) Len

func (m *Map[V]) Len() int

Len reports the number of resident records across both generations, including any not yet reclaimed by a read.

func (*Map[V]) Load

func (m *Map[V]) Load(key string) (V, bool)

Load returns the value for key. A hit in the previous generation is promoted into the live one, so an in-use key is not dropped by the next rotation. An expired entry reads as absent and is dropped.

func (*Map[V]) LoadOrStore

func (m *Map[V]) LoadOrStore(key string, value V, ttl time.Duration) (actual V, loaded bool)

LoadOrStore returns the existing live value for key, or stores and returns value when there is none. loaded reports which happened.

func (*Map[V]) Store

func (m *Map[V]) Store(key string, value V, ttl time.Duration)

Store sets key for ttl (ttl <= 0 never expires), rotating generations when the live one is full.

Jump to

Keyboard shortcuts

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