pub struct AsyncKeyedCache<K, V>{ /* private fields */ }Expand description
A bounded keyed cache where each key has its own async lock.
lookup acquires the key’s lock and returns an
AsyncKeyedCacheEntry that holds it for the entry’s lifetime. While the entry is
held, get/insert/remove/take operate on that key’s slot atomically with
respect to other lookups of the same key; other keys are never blocked.
This encapsulates the common “lock the key, check the cache, maybe fill it, all without racing another filler” pattern in one place, so the lock and the cache can’t drift out of sync.
Implementations§
Source§impl<K, V> AsyncKeyedCache<K, V>
impl<K, V> AsyncKeyedCache<K, V>
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new keyed cache holding at most capacity entries (LRU eviction).
Sourcepub async fn lookup(&self, key: K) -> AsyncKeyedCacheEntry<K, V>
pub async fn lookup(&self, key: K) -> AsyncKeyedCacheEntry<K, V>
Lock key and return an entry for operating on its cache slot. The key stays
locked until the returned entry is dropped; other keys are not blocked.
Trait Implementations§
Source§impl<K, V> Clone for AsyncKeyedCache<K, V>
impl<K, V> Clone for AsyncKeyedCache<K, V>
Source§fn clone(&self) -> AsyncKeyedCache<K, V>
fn clone(&self) -> AsyncKeyedCache<K, V>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<K, V> !RefUnwindSafe for AsyncKeyedCache<K, V>
impl<K, V> !UnwindSafe for AsyncKeyedCache<K, V>
impl<K, V> Freeze for AsyncKeyedCache<K, V>
impl<K, V> Send for AsyncKeyedCache<K, V>
impl<K, V> Sync for AsyncKeyedCache<K, V>
impl<K, V> Unpin for AsyncKeyedCache<K, V>
impl<K, V> UnsafeUnpin for AsyncKeyedCache<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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