Struct MultiCache

Source
pub struct MultiCache<K, V> { /* private fields */ }

Implementations§

Source§

impl<K, V> MultiCache<K, V>

Source

pub fn new(bytesize: usize) -> MultiCache<K, V>
where K: Hash + Eq,

Create a new cache which will at most hold a total of bytesize in elements

Source

pub fn put(&self, key: K, value: V, bytes: usize)
where K: Hash + Eq,

Add a new element by key/value with a given bytesize, if after inserting this element we would be going over the bytesize of the cache first enough elements are evicted for that to not be the case

Source

pub fn put_arc(&self, key: K, value: Arc<V>, bytes: usize)
where K: Hash + Eq,

Add a new element by key/Arc with a given bytesize, if after inserting this element we would be going over the bytesize of the cache first enough elements are evicted for that to not be the case

Source

pub fn get(&self, key: &K) -> Option<Arc<V>>
where K: Hash + Eq,

Get an element from the cache, updating it so it’s now the most recently used and thus the last to be evicted

Source

pub fn remove(&self, key: &K) -> Option<Arc<V>>
where K: Hash + Eq,

Remove an element from the cache, returning it if it exists

Source

pub fn contains_key(&self, key: &K) -> bool
where K: Hash + Eq,

Check if a given key exists in the cache

Trait Implementations§

Source§

impl<K: Debug, V: Debug> Debug for MultiCache<K, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V> !Freeze for MultiCache<K, V>

§

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

§

impl<K, V> Send for MultiCache<K, V>
where K: Send, V: Sync + Send,

§

impl<K, V> Sync for MultiCache<K, V>
where K: Send, V: Sync + Send,

§

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

§

impl<K, V> UnwindSafe for MultiCache<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.