Skip to main content

Module cache

Module cache 

Source
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 lock, registry, or background task.

Cross-track ordering comes from one statistic: the mean last-access time of the evictable population (every cached group except each track’s protected latest). A group accessed more recently than that mean is never evicted, so a fresh fetch 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.

A pool is inert by default (Pool::unbounded): publishers and subscribers that never set a capacity pay only a couple of atomic counters. A relay creates one bounded pool and shares it across every origin so the whole process caches into a single budget.

Structs§

Pool
A shared byte budget that caches charge into; cloning shares the same budget.