pub struct Pool { /* private fields */ }Expand description
A shared cache policy and byte budget; cloning shares both.
The pool tracks how many payload bytes are cached across every registered group,
plus the mean last-access time of the evictable ones. It never evicts on its own:
tracks accrue eviction debt as they write and evict their own oldest groups to
pay it. Idle expiration runs during Self::gc. The capacity is
therefore a target usage converges toward, not a hard limit: carried debt, capped
payments, and the always-protected live edge all let usage transiently exceed it.
Implementations§
Source§impl Pool
impl Pool
Sourcepub fn new(config: Config) -> Self
pub fn new(config: Config) -> Self
Create a pool from an initial policy.
The budget counts frame payload bytes plus a fixed cost per cached group, which
is most of what a group carrying one small frame occupies. It is not process
RSS, and it is a convergence target rather than a hard limit; leave headroom
when sizing it from real memory. The expiry is fixed, while the capacity can
later be changed with Self::resize.
Sourcepub fn resize(&self, capacity: impl Into<Option<u64>>)
pub fn resize(&self, capacity: impl Into<Option<u64>>)
Change the capacity. None makes the pool unbounded.
Takes effect as tracks write: a shrink leaves the pool over budget, which every subsequent write pays down proportionally. Nothing is reclaimed synchronously.
Sourcepub fn expiry(&self) -> Option<Duration>
pub fn expiry(&self) -> Option<Duration>
The wall-clock LRU window, or None when idle content is never reclaimed.
Sourcepub fn gc(&self, now: Instant) -> Option<Instant>
pub fn gc(&self, now: Instant) -> Option<Instant>
Collect idle cache entries and return the next cleanup time.
Call after polling and at the returned deadline, including when idle. Calls before that deadline only advance the pool’s sampled clock. A due pass visits every cached group, dating accesses since the last pass and reclaiming idle groups except each track’s latest. Delayed calls extend retention. Shared pools use the latest supplied instant.
None means both cache policies are disabled. After enabling a capacity
with Self::resize, call this again to resume periodic clock sampling.