cell

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.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

Overview

Package cell owns long-lived runtime state (counters, breaker copies, rotation state, shared caches) keyed by stable ids, so the state outlives the published generations that point at it. A cell is created on first Acquire and linked to the derived object being built; the engine reports at each publish which cells the new generation links, and Expire drops cells left unlinked for longer than IdleTTL.

Out of scope: what a cell holds, how it syncs with a store, and any timer: the registry runs no goroutine, the caller drives Expire.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Acquire

func Acquire[T any](r *Registry, l Linker, k Key, mk func() *T) *T

Acquire returns the cell for k, creating it with mk on first use, and links it to l's output (nil l links nothing). The returned address never changes while the cell is registered. mk runs under the registry lock and must not call Acquire.

Types

type Key

type Key struct {
	Type string
	ID   string
}

Key identifies a cell: a type name and an id the owner builds from stable ids. Type keeps two cell types from colliding on one id.

type Linker

type Linker interface{ Link(Key) }

Linker is what Acquire needs from the caller: a way to say "the object I am building uses this cell". The engine's transaction implements it.

type Options

type Options struct {
	// IdleTTL is how long an unlinked cell survives before Expire drops it.
	// Linked and pinned cells never expire.
	IdleTTL time.Duration
	// OnDrop is called with the cell value when it leaves the registry, so a
	// type that holds store-side state can flush it.
	OnDrop func(k Key, v any)
}

Options sets the registry's expiry policy.

type Registry

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

Registry owns every cell in the process. One per process.

func NewRegistry

func NewRegistry(o Options) *Registry

NewRegistry returns an empty registry.

func (*Registry) Expire

func (r *Registry) Expire(now time.Time) int

Expire drops every unpinned cell left unlinked for at least IdleTTL and returns how many it dropped.

func (*Registry) Len

func (r *Registry) Len() int

Len is the live cell count, for a gauge.

func (r *Registry) Link(k Key)

Link pins k. It makes the registry a Linker, so Acquire(r, r, k, mk) obtains a cell that no plan references and that never expires.

func (*Registry) Pin

func (r *Registry) Pin(k Key)

Pin marks a cell as always linked, for cells no plan references (the revocation set). Pinning a key before its first Acquire is allowed.

Jump to

Keyboard shortcuts

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