Struct MemoryLruCache

Source
pub struct MemoryLruCache<K, V> { /* private fields */ }
Expand description

An LRU-cache which operates on memory used.

Implementations§

Source§

impl<K: Eq + Hash, V: ResidentSize> MemoryLruCache<K, V>

Source

pub fn new(max_size: usize) -> Self

Create a new cache with a maximum cumulative size of values.

Source

pub fn insert(&mut self, key: K, val: V)

Insert an item.

Source

pub fn get(&mut self, key: &K) -> Option<&V>

Get a reference to an item in the cache. It is a logic error for its heap size to be altered while borrowed.

Source

pub fn with_mut<U>( &mut self, key: &K, with: impl FnOnce(Option<&mut V>) -> U, ) -> U

Execute a closure with the value under the provided key.

Source

pub fn current_size(&self) -> usize

Currently-used size of values in bytes.

Source

pub fn len(&self) -> usize

Returns the number of key-value pairs that are currently in the cache.

Source

pub fn contains(&self, key: &K) -> bool

Returns a bool indicating whether the given key is in the cache. Does not update the LRU list.

Source

pub fn is_empty(&self) -> bool

Returns a bool indicating whether the cache is empty or not.

Source

pub fn peek(&self, key: &K) -> Option<&V>

Returns a reference to the value corresponding to the key in the cache or None if it is not present in the cache. Unlike get, peek does not update the LRU list so the key’s position will be unchanged.

Auto Trait Implementations§

§

impl<K, V> Freeze for MemoryLruCache<K, V>

§

impl<K, V> RefUnwindSafe for MemoryLruCache<K, V>

§

impl<K, V> Send for MemoryLruCache<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for MemoryLruCache<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for MemoryLruCache<K, V>

§

impl<K, V> UnwindSafe for MemoryLruCache<K, V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.