Struct sn_routing::Cache[][src]

pub struct Cache<T, V> where
    T: Hash + Eq + Copy
{ /* fields omitted */ }

A BTreeMap-backed cache supporting capacity- and duration-based expiry.

Implementations

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]

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]

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]

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]

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]

Remove an item from the cache, returning the removed value.

pub async fn clear(&self)[src]

Clear the cache, removing all items.

Trait Implementations

impl<T: Debug, V: Debug> Debug for Cache<T, V> where
    T: Hash + Eq + Copy
[src]

Auto Trait Implementations

impl<T, V> !RefUnwindSafe for Cache<T, V>

impl<T, V> Send for Cache<T, V> where
    T: Send,
    V: Send

impl<T, V> Sync for Cache<T, V> where
    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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,