Struct SimpleCache

Source
pub struct SimpleCache<K: Eq + Hash + Copy + Send + Sync, V: Send + Sync> { /* private fields */ }
Expand description

This struct implements a simple value cache that holds up to a certain number of entries at a time.

When it reaches its maximum capacity it will drop the oldest unused entries.

All methods of this struct are thread-safe.

Implementations§

Source§

impl<K: Eq + Hash + Copy + Send + Sync, V: Send + Sync> SimpleCache<K, V>

Source

pub fn new(max_size: usize) -> Self

Creates a new SimpleCache with a given capacity.

Arguments:

  • max_size: Maximum number of items in the cache;

Trait Implementations§

Source§

impl<K: Eq + Hash + Copy + Send + Sync, V: Send + Sync> ValueCache<K, V> for SimpleCache<K, V>

Source§

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

Gets the value from the cache if it exists. Read more
Source§

fn insert(&self, key: K, value: &Arc<V>)

Inserts the value into the cache. Reinserting a new value with the same key will replace the existing value. Read more
Source§

fn clear(&self)

Removes all entries from the cache.
Source§

fn len(&self) -> usize

Returns the number of entries in the cache.
Source§

fn is_empty(&self) -> bool

Returns true if the cache is empty or false otherwise.

Auto Trait Implementations§

§

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

§

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

§

impl<K, V> Send for SimpleCache<K, V>

§

impl<K, V> Sync for SimpleCache<K, V>

§

impl<K, V> Unpin for SimpleCache<K, V>
where K: Unpin,

§

impl<K, V> UnwindSafe for SimpleCache<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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V