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, Value: 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 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.
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.
fn contains_key(&mut self, key: &Key) -> bool
Returns whether key
exists in the cache or not. Also removes expired elements.
fn len(&mut self) -> usize
Returns the size of the cache, i.e. the number of cached key-value pairs. Also removes expired elements.
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.
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.
fn entry(&mut self, key: Key) -> Entry<Key, Value>
Gets the given key's corresponding entry in the map for in-place manipulation.
Trait Implementations
impl<Key: Clone, Value: Clone> Clone for LruCache<Key, Value>
[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