Skip to main content

Pool

Struct Pool 

Source
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

Source

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.

Source

pub fn unbounded() -> Self

Create a pool that never evicts. This is the Default.

Source

pub fn capacity(&self) -> Option<u64>

The configured byte target, or None when unbounded.

Source

pub fn used(&self) -> u64

Bytes currently cached across every registered group.

Source

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.

Source

pub fn expiry(&self) -> Option<Duration>

The wall-clock LRU window, or None when idle content is never reclaimed.

Source

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.

Source

pub fn downgrade(&self) -> PoolWeak

A handle that reaches this budget without keeping it alive.

Trait Implementations§

Source§

impl Clone for Pool

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Pool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Pool

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Pool

§

impl RefUnwindSafe for Pool

§

impl Send for Pool

§

impl Sync for Pool

§

impl Unpin for Pool

§

impl UnsafeUnpin for Pool

§

impl UnwindSafe for Pool

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more