pub struct ClawCache<K, V> { /* private fields */ }Expand description
Implementations§
Source§impl<K, V> ClawCache<K, V>
impl<K, V> ClawCache<K, V>
Sourcepub fn new(capacity: usize) -> ClawResult<Self>
pub fn new(capacity: usize) -> ClawResult<Self>
Create a new cache with the given maximum capacity (number of entries).
§Errors
Returns ClawError::Cache if capacity is zero.
Sourcepub fn insert(&mut self, key: K, value: V)
pub fn insert(&mut self, key: K, value: V)
Insert value under key. If the cache is full, the LRU entry is
evicted first.
Sourcepub fn get(&mut self, key: &K) -> Option<&V>
pub fn get(&mut self, key: &K) -> Option<&V>
Return a reference to the cached value for key, or None if not
present. Accessing an entry marks it as most-recently used.
Sourcepub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
Remove and return the value for key, if present.
Sourcepub fn invalidate(&mut self, key: &K)
pub fn invalidate(&mut self, key: &K)
Invalidate (remove) the value for key, if present.
Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for ClawCache<K, V>
impl<K, V> RefUnwindSafe for ClawCache<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for ClawCache<K, V>
impl<K, V> Sync for ClawCache<K, V>
impl<K, V> Unpin for ClawCache<K, V>
impl<K, V> UnsafeUnpin for ClawCache<K, V>
impl<K, V> UnwindSafe for ClawCache<K, V>where
K: UnwindSafe,
V: UnwindSafe,
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> 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