[][src]Struct lru_time_cache::LruCache

pub struct LruCache<Key, Value> { /* fields omitted */ }

Implementation of LRU cache.

Implementations

impl<Key, Value> LruCache<Key, Value> where
    Key: Ord + Clone
[src]

pub fn with_capacity(capacity: usize) -> LruCache<Key, Value>[src]

Constructor for capacity based LruCache.

pub fn with_expiry_duration(time_to_live: Duration) -> LruCache<Key, Value>[src]

Constructor for time based LruCache.

pub fn with_expiry_duration_and_capacity(
    time_to_live: Duration,
    capacity: usize
) -> LruCache<Key, Value>
[src]

Constructor for dual-feature capacity and time based LruCache.

pub fn notify_insert(
    &mut self,
    key: Key,
    value: Value
) -> (Option<Value>, Vec<(Key, Value)>)
[src]

Inserts a key-value pair into the cache.

If the key already existed in the cache, the existing value is returned and overwritten in the cache. Otherwise, the key-value pair is inserted and None is returned. Evicts and returns expired entries.

pub fn insert(&mut self, key: Key, value: Value) -> Option<Value>[src]

Inserts a key-value pair into the cache.

If the key already existed in the cache, the existing value is returned and overwritten in the cache. Otherwise, the key-value pair is inserted and None is returned.

pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<Value> where
    Key: Borrow<Q>,
    Q: Ord
[src]

Removes a key-value pair from the cache.

pub fn clear(&mut self)[src]

Clears the LruCache, removing all values.

pub fn notify_get<Q: ?Sized>(
    &mut self,
    key: &Q
) -> (Option<&Value>, Vec<(Key, Value)>) where
    Key: Borrow<Q>,
    Q: Ord
[src]

Much like get(), except in addition returns expired entries.

pub fn get<Q: ?Sized>(&mut self, key: &Q) -> Option<&Value> where
    Key: Borrow<Q>,
    Q: Ord
[src]

Retrieves a reference to the value stored under key, or None if the key doesn't exist. Also removes expired elements and updates the time.

pub fn peek<Q: ?Sized>(&self, key: &Q) -> Option<&Value> where
    Key: Borrow<Q>,
    Q: Ord
[src]

Returns a reference to the value with the given key, if present and not expired, without updating the timestamp.

pub fn notify_get_mut<Q: ?Sized>(
    &mut self,
    key: &Q
) -> (Option<&mut Value>, Vec<(Key, Value)>) where
    Key: Borrow<Q>,
    Q: Ord
[src]

Retrieves a mutable reference to the value stored under key, or None if the key doesn't exist. Also removes expired elements and updates the time.

pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut Value> where
    Key: Borrow<Q>,
    Q: Ord
[src]

Retrieves a mutable reference to the value stored under key, or None if the key doesn't exist. Also removes expired elements and updates the time.

pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
    Key: Borrow<Q>,
    Q: Ord
[src]

Returns whether key exists in the cache or not.

pub fn len(&self) -> usize[src]

Returns the size of the cache, i.e. the number of cached non-expired key-value pairs.

pub fn is_empty(&self) -> bool[src]

Returns true if there are no non-expired entries in the cache.

pub fn entry(&mut self, key: Key) -> Entry<'_, Key, Value>[src]

Gets the given key's corresponding entry in the map for in-place manipulation.

pub fn notify_iter(&mut self) -> NotifyIter<'_, Key, Value>

Notable traits for NotifyIter<'a, Key, Value>

impl<'a, Key, Value> Iterator for NotifyIter<'a, Key, Value> where
    Key: Ord + Clone
type Item = TimedEntry<'a, Key, Value>;
[src]

Returns an iterator over all entries that updates the timestamps as values are traversed. Also removes expired elements before creating the iterator. Values are produced in the most recently used order.

Also, evicts and returns expired entries.

pub fn iter(&mut self) -> Iter<'_, Key, Value>

Notable traits for Iter<'a, Key, Value>

impl<'a, Key, Value> Iterator for Iter<'a, Key, Value> where
    Key: Ord + Clone
type Item = (&'a Key, &'a Value);
[src]

Returns an iterator over all entries that updates the timestamps as values are traversed. Also removes expired elements before creating the iterator. Values are produced in the most recently used order.

pub fn peek_iter(&self) -> PeekIter<'_, Key, Value>

Notable traits for PeekIter<'a, Key, Value>

impl<'a, Key, Value> Iterator for PeekIter<'a, Key, Value> where
    Key: Ord + Clone
type Item = (&'a Key, &'a Value);
[src]

Returns an iterator over all entries that does not modify the timestamps.

Trait Implementations

impl<Key, Value> Clone for LruCache<Key, Value> where
    Key: Clone,
    Value: Clone
[src]

Auto Trait Implementations

impl<Key, Value> RefUnwindSafe for LruCache<Key, Value> where
    Key: RefUnwindSafe,
    Value: RefUnwindSafe

impl<Key, Value> Send for LruCache<Key, Value> where
    Key: Send,
    Value: Send

impl<Key, Value> Sync for LruCache<Key, Value> where
    Key: Sync,
    Value: Sync

impl<Key, Value> Unpin for LruCache<Key, Value> where
    Key: Unpin

impl<Key, Value> UnwindSafe for LruCache<Key, Value> where
    Key: RefUnwindSafe + UnwindSafe,
    Value: 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, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.