pub struct PlanCache<K, V> { /* private fields */ }Expand description
Concurrent bounded preparation. Returned Arcs pin values. The additional
idle predicate protects work whose output or completion outlives that Arc.
Failed or panicking loaders release capacity and wake waiters for retry.
Implementations§
Source§impl<K: Clone + Eq + Hash, V> PlanCache<K, V>
impl<K: Clone + Eq + Hash, V> PlanCache<K, V>
Sourcepub fn new(capacity: usize, idle: fn(&V) -> bool) -> Result<Self>
pub fn new(capacity: usize, idle: fn(&V) -> bool) -> Result<Self>
Set the maximum number of resident/preparing plans, never zero.
Sourcepub fn get_or_prepare(
&self,
key: K,
load: impl FnOnce() -> Result<V>,
) -> Result<Arc<V>>
pub fn get_or_prepare( &self, key: K, load: impl FnOnce() -> Result<V>, ) -> Result<Arc<V>>
Reuse or prepare a value. Concurrent requests for the same key share one
outcome; other keys may prepare concurrently. Returns Busy when all
capacity is pinned or preparing. No loader executes under the cache lock.
Sourcepub fn statistics(&self) -> CacheStatistics
pub fn statistics(&self) -> CacheStatistics
Snapshot cache counters without waiting for preparation.
Auto Trait Implementations§
impl<K, V> !Freeze for PlanCache<K, V>
impl<K, V> RefUnwindSafe for PlanCache<K, V>
impl<K, V> Send for PlanCache<K, V>
impl<K, V> Sync for PlanCache<K, V>
impl<K, V> Unpin for PlanCache<K, V>
impl<K, V> UnsafeUnpin for PlanCache<K, V>
impl<K, V> UnwindSafe for PlanCache<K, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more