Struct sn_routing::Cache [−][src]
A BTreeMap
-backed cache supporting capacity- and duration-based expiry.
Implementations
impl<T, V> Cache<T, V> where
T: Ord + Hash + Copy,
[src]
impl<T, V> Cache<T, V> where
T: Ord + Hash + Copy,
[src]pub fn with_capacity(capacity: usize) -> Self
[src]
Creating capacity based Cache
.
pub fn with_expiry_duration(duration: Duration) -> Self
[src]
Creating time based Cache
.
pub fn with_expiry_duration_and_capacity(
duration: Duration,
capacity: usize
) -> Self
[src]
duration: Duration,
capacity: usize
) -> Self
Creating dual-feature capacity and time based Cache
.
pub async fn len(&self) -> usize
[src]
Returns the number of items in the cache.
pub async fn is_empty(&self) -> bool
[src]
Returns true
if the cache contains no items.
pub async fn count<P>(&self, predicate: P) -> usize where
P: FnMut(&(&T, &Item<V>)) -> bool,
[src]
P: FnMut(&(&T, &Item<V>)) -> bool,
Returns the number of items in the cache that match the given predicate.
pub async fn get(&self, key: &T) -> Option<V> where
T: Eq + Hash,
V: Clone,
[src]
T: Eq + Hash,
V: Clone,
Get a value from the cache if one is set and not expired.
A clone of the value is returned, so this is only implemented when V: Clone
.
pub async fn set(
&self,
key: T,
value: V,
custom_duration: Option<Duration>
) -> Option<V> where
T: Eq + Hash + Clone,
[src]
&self,
key: T,
value: V,
custom_duration: Option<Duration>
) -> Option<V> where
T: Eq + Hash + Clone,
Set a value in the cache and return the previous value, if any.
This will override an existing value for the same key, if there is one. custom_duration
can be set to override self.item_duration
. If the new item causes the cache to exceed its
capacity, the oldest entry in the cache will be removed.
pub async fn remove_expired(&self)
[src]
Remove expired items from the cache storage.
pub async fn remove(&self, key: &T) -> Option<V> where
T: Eq + Hash,
[src]
T: Eq + Hash,
Remove an item from the cache, returning the removed value.
pub async fn clear(&self)
[src]
Clear the cache, removing all items.
Trait Implementations
Auto Trait Implementations
impl<T, V> !RefUnwindSafe for Cache<T, V>
impl<T, V> Send for Cache<T, V> where
T: Send,
V: Send,
T: Send,
V: Send,
impl<T, V> Sync for Cache<T, V> where
T: Send + Sync,
V: Send + Sync,
T: Send + Sync,
V: Send + Sync,
impl<T, V> Unpin for Cache<T, V>
impl<T, V> UnwindSafe for Cache<T, V> where
T: RefUnwindSafe,
V: RefUnwindSafe,
T: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,