Struct lru_time_cache::LruCache [] [src]

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

Implementation of LRU cache.

Methods

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

fn with_capacity(capacity: usize) -> LruCache<Key, Value>

Constructor for capacity based LruCache.

fn with_expiry_duration(time_to_live: Duration) -> LruCache<Key, Value>

Constructor for time based LruCache.

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

Constructor for dual-feature capacity and time based LruCache.

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

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.

fn remove(&mut self, key: &Key) -> Option<Value>

Removes a key-value pair from the cache.

fn clear(&mut self)

Clears the LruCache, removing all values.

fn get(&mut self, key: &Key) -> Option<&Value>

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.

fn peek(&self, key: &Key) -> Option<&Value>

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

fn get_mut(&mut self, key: &Key) -> Option<&mut Value>

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.

fn contains_key(&self, key: &Key) -> bool

Returns whether key exists in the cache or not.

fn len(&self) -> usize

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

fn is_empty(&self) -> bool

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

fn entry(&mut self, key: Key) -> Entry<Key, Value>

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

fn peek_iter(&self) -> PeekIterator<Key, Value>

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

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

fn retrieve_all(&mut self) -> Vec<(Key, Value)>

Returns a clone of all elements as an unordered vector of key-value tuples. Also removes expired elements and updates the time.

fn retrieve_all_ordered(&mut self) -> Vec<(Key, Value)>

Returns a clone of all elements as a vector of key-value tuples ordered by most to least recently updated. Also removes expired elements and updates the time.

Trait Implementations

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

fn clone(&self) -> LruCache<Key, Value>

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more