Struct lru_time_cache::LruCache [−][src]
Implementation of LRU cache.
Implementations
impl<Key, Value> LruCache<Key, Value> where
Key: Ord + Clone,
[src]
Key: Ord + Clone,
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]
time_to_live: Duration,
capacity: usize
) -> LruCache<Key, Value>
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]
&mut self,
key: Key,
value: Value
) -> (Option<Value>, Vec<(Key, 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.
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]
Key: Borrow<Q>,
Q: Ord,
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]
&mut self,
key: &Q
) -> (Option<&Value>, Vec<(Key, Value)>) where
Key: Borrow<Q>,
Q: Ord,
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]
Key: Borrow<Q>,
Q: Ord,
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]
Key: Borrow<Q>,
Q: Ord,
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]
&mut self,
key: &Q
) -> (Option<&mut Value>, Vec<(Key, Value)>) where
Key: Borrow<Q>,
Q: Ord,
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]
Key: Borrow<Q>,
Q: Ord,
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]
Key: Borrow<Q>,
Q: Ord,
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]
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>;
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>ⓘ
[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>ⓘ
[src]
Returns an iterator over all entries that does not modify the timestamps.
Trait Implementations
Auto Trait Implementations
impl<Key, Value> RefUnwindSafe for LruCache<Key, Value> where
Key: RefUnwindSafe,
Value: RefUnwindSafe,
Key: RefUnwindSafe,
Value: RefUnwindSafe,
impl<Key, Value> Send for LruCache<Key, Value> where
Key: Send,
Value: Send,
Key: Send,
Value: Send,
impl<Key, Value> Sync for LruCache<Key, Value> where
Key: Sync,
Value: Sync,
Key: Sync,
Value: Sync,
impl<Key, Value> Unpin for LruCache<Key, Value> where
Key: Unpin,
Key: Unpin,
impl<Key, Value> UnwindSafe for LruCache<Key, Value> where
Key: RefUnwindSafe + UnwindSafe,
Value: RefUnwindSafe,
Key: RefUnwindSafe + UnwindSafe,
Value: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,