Expand description
A shared byte budget for cached groups, repaid by write-time eviction.
Every group charges its cached bytes into a Pool through a crate-internal
Charge, billed to its track’s Track account. The pool itself never evicts: it is
a handful of atomic counters. While the pool is over capacity, each track accrues
eviction debt as it writes (accrue),
sized proportionally to what it wrote, and pays that debt by aborting its own oldest
groups with Error::Evicted. Reclamation is therefore
distributed across every writing track and converges on the capacity without any
global eviction task. A capacity below what the pool pins (each live track’s newest
group) converges on the pins instead: nothing owes debt for bytes no eviction can free.
Cross-track ordering comes from one statistic: the mean last-access time of the evictable population (every cached group except each live track’s protected latest). A group accessed more recently than that mean is never evicted, so freshly read or fetched content in one track can’t die while another track holds staler content, and a track whose oldest group is staler than the mean accrues debt at double rate. Evicting old entries and inserting new ones both advance the mean, so the eviction frontier moves with cache turnover on its own.
The pool also owns the wall-clock LRU window (Pool::expiry): a group that
nobody has read or written for that long is reclaimed, no matter what retention
its track advertises. Only a live track’s latest group is exempt: once a track
ends, a stale consumer can’t pin any of it. Track retention
(max_age) decides which groups readers skip as
stale; the pool’s expiry is the orthogonal bound that frees the bytes of content
nobody touches.
Expiry is driven by Pool::poll, also called by each origin driver.
Reads and writes clear the expiration timestamp without reading a clock.
The next cleanup pass dates that activity at its supplied instant. Delayed
cleanup extends retention; standalone pools must call poll too.
Byte-pressure eviction still runs inline on writes.
The pool never evicts a live track’s latest group, so a session’s live-edge budget
(session::Limits::live_edges) bounds what those hold in bytes: every track a session
ingests bills its live edge there, and a session past its budget pays with its own
live edges in delivery’s priority order, never another session’s.
A bare pool is inert by default (Pool::unbounded): publishers and subscribers
that never set a capacity or expiry pay only a couple of atomic counters, and
register nothing. A standalone origin enables
DEFAULT_EXPIRY, while a relay creates one configured pool and shares it across
every origin so the whole process caches into a single policy.
Structs§
- Config
- The initial policy for a
Pool. - Pool
- A shared cache policy and byte budget; cloning shares both.
- Pool
Weak - A handle to a
Poolthat does not keep the budget alive.
Constants§
- DEFAULT_
EXPIRY - Default idle window for standalone origins and relays.