bufferbudget

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0, AGPL-3.0 Imports: 5 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

View Source
var ErrReservation = errors.New("buffer does not own a matching live reservation")

Functions

This section is empty.

Types

type Account

type Account[K comparable] struct {
	// contains filtered or unexported fields
}

func NewAccount

func NewAccount[K comparable](budget *Budget, limit uint64) *Account[K]

func (*Account[K]) Available

func (a *Account[K]) Available(bytes uint64) bool

Available includes reclaimable cache, but never output or authentication holdings. Selection can inspect pressure without allocating and rolling back.

func (*Account[K]) Close

func (a *Account[K]) Close() error

Close retires the account's cache after its workers have joined. Independently delivered buffers stay charged and are reported instead of being revoked.

func (*Account[K]) Reserve

func (a *Account[K]) Reserve(bytes uint64) (Reservation, bool)

func (*Account[K]) Store

func (a *Account[K]) Store(key K, data []byte, reservation Reservation) (*Cached[K], error)

Store consumes a matching reservation without changing the charged total. Rejecting an invalid handoff leaves the caller's ownership untouched.

func (*Account[K]) TakeEvicted

func (a *Account[K]) TakeEvicted() []*Cached[K]

TakeEvicted transfers pressure-eviction records to the account owner, so index cleanup follows actual evictions instead of scanning live cache entries.

func (*Account[K]) Used

func (a *Account[K]) Used() uint64

type Budget

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

Budget owns both retained copies and immediately reclaimable cache across receivers. Cache eviction never calls another receiver while holding a lock.

func New

func New(limit uint64) (*Budget, error)

func (*Budget) Changes

func (b *Budget) Changes() <-chan struct{}

Changes must be observed before checking capacity so a release between the check and the wait cannot be missed.

func (*Budget) Close

func (b *Budget) Close() error

func (*Budget) Limit

func (b *Budget) Limit() uint64

func (*Budget) Used

func (b *Budget) Used() uint64

func (*Budget) Wake

func (b *Budget) Wake()

type Cached

type Cached[K comparable] struct {
	// contains filtered or unexported fields
}

func (*Cached[K]) Copy

func (c *Cached[K]) Copy() (data []byte, reservation Reservation, live bool)

Copy pins its source while reserving an independent delivery. A nil copy with live=true means capacity, not content, is absent.

func (*Cached[K]) Drop

func (c *Cached[K]) Drop()

func (*Cached[K]) Key

func (c *Cached[K]) Key() K

func (*Cached[K]) Live

func (c *Cached[K]) Live() bool

type Reservation

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

Reservation carries the account and exact bytes that can be returned. Value copies share one claim, and an old copy cannot release a transferred claim.

func (Reservation) Bytes

func (r Reservation) Bytes() uint64

func (Reservation) Release

func (r Reservation) Release() bool

func (Reservation) Split

func (r Reservation) Split(bytes uint64) (Reservation, bool)

Split preserves the aggregate admission: canonical data, output delivery, and an admitted attempt may separate only after their total capacity was reserved.

func (Reservation) Transfer

func (r Reservation) Transfer() (Reservation, bool)

Jump to

Keyboard shortcuts

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