cache

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cache provides owner-serialized caches with deterministic LRU eviction Values are caller-owned immutable snapshots. Costs are logical retained bytes, not process RSS; keys and fixed entry overhead are charged automatically

Index

Constants

View Source
const MaxBytes = 64 << 20
View Source
const MaxEntries = 65536
View Source
const MaxTime int64 = 9007199254740991

Variables

This section is empty.

Functions

This section is empty.

Types

type Budget

type Budget struct {
	// contains filtered or unexported fields
}

Budget bounds aggregate retained data shared by several snapshots

func NewBudget

func NewBudget(limit int) (*Budget, error)

Create a shared logical-byte reservation budget

func (*Budget) Release

func (b *Budget) Release(size int) error

Release a valid outstanding byte reservation

func (*Budget) Reserve

func (b *Budget) Reserve(size int) bool

Atomically reserve bytes when capacity permits

func (*Budget) Used

func (b *Budget) Used() int

Read the currently reserved logical bytes

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any](capacity, bytes int) (*Cache[T], error)

Create an entry-count and byte-bounded cache

func (*Cache[T]) Bytes

func (c *Cache[T]) Bytes() int

Return the cache logical byte charge

func (*Cache[T]) Clear

func (c *Cache[T]) Clear()

Discard all cache entries and reset byte accounting

func (*Cache[T]) Delete

func (c *Cache[T]) Delete(key string) bool

Remove an entry and release its charged bytes

func (*Cache[T]) Entries

func (c *Cache[T]) Entries(now int64) ([]Entry[T], error)

Collect current entries after validating the supplied clock

func (*Cache[T]) Get

func (c *Cache[T]) Get(key string, now int64) (T, bool)

Read an unexpired entry and update its LRU position

func (*Cache[T]) Len

func (c *Cache[T]) Len() int

Return the number of retained entries

func (*Cache[T]) Peek

func (c *Cache[T]) Peek(key string, now int64) (T, bool)

Read an unexpired entry without changing recency

func (*Cache[T]) Put

func (c *Cache[T]) Put(key string, value T, cost int, expires, now int64) ([]string, error)

Insert a bounded entry and evict eligible older entries

func (*Cache[T]) Trim

func (c *Cache[T]) Trim(reserved int, now int64) ([]string, error)

Trim reserves space for an additional owner-held snapshot (such as an index)

type Entry

type Entry[T any] struct {
	Key     string
	Value   T
	Cost    int
	Expires int64
	// contains filtered or unexported fields
}

type Persistence

type Persistence[T any] struct {
	// contains filtered or unexported fields
}

Persistence explicitly uses a caller-selected private host namespace. No fallback Flush uses bounded atomic batches and managed-state receipt recovery

func NewPersistence

func NewPersistence[T any](backend managedstate.PrivateBackend) (*Persistence[T], error)

Bind cache persistence to an explicitly selected private backend

func (*Persistence[T]) Flush

func (p *Persistence[T]) Flush(ctx context.Context, c *Cache[T], now int64) error

Flush cache changes in bounded private-storage batches

func (*Persistence[T]) Load

func (p *Persistence[T]) Load(ctx context.Context, c *Cache[T], now int64) error

Restore validated cache entries without partially replacing the cache

Jump to

Keyboard shortcuts

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