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 groups. 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::poll. 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 poll(&self, now: Instant, waiter: &Waiter) -> Option<Instant>
pub fn poll(&self, now: Instant, waiter: &Waiter) -> Option<Instant>
Collect idle cache entries and return the next cleanup time, like
Driver::poll.
Call at the returned deadline, and again whenever waiter wakes, 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 live track’s latest. Delayed calls extend
retention. Shared pools use the latest supplied instant.
None means both cache policies are disabled and no read waits on a wall-clock
deadline. After enabling a capacity
with Self::resize, call this again to resume periodic clock sampling.
It also releases reads parked on a wall-clock deadline (a group’s successor
arriving plus the reader’s budget), so the returned deadline includes the earliest
of those, and waiter wakes when a read arms one earlier than it. Until a pool is
first collected, no deadline fires; that first collection wakes the reads waiting
on one so they arm it.