Struct Cache

Source
pub struct Cache<K> { /* private fields */ }
Expand description

A thread-safe concurrent cache from key K to arbitrarily typed values

Implementations§

Source§

impl<K: Hash + Eq> Cache<K>

Source

pub fn new(num_pages: usize, page_size: usize) -> Self

Create a new cache setting page size and number of pages.

page_size determines the maximum size of values that can be stored in the cache.

num pages determines how many slabs of memory of this size should be allocated.

Each page has its own read-write lock, so the more pages you have, the less likely you are to have lock contention.

Source

pub fn insert<V: 'static>(&self, key: K, val: V) -> Cached<'_, V>

Insert a value V into cache with key K, returns a Cached to the newly stored or spilled value

NOTE If you insert different values under the same key, you will only get one of them out again. Updates are not possible.

Source

pub fn get<'a, V: 'static>(&'a self, key: &K) -> Option<Cached<'a, V>>

Is this value in the cache?

Trait Implementations§

Source§

impl<K> Send for Cache<K>

Source§

impl<K> Sync for Cache<K>

Auto Trait Implementations§

§

impl<K> Freeze for Cache<K>

§

impl<K> !RefUnwindSafe for Cache<K>

§

impl<K> Unpin for Cache<K>
where K: Unpin,

§

impl<K> UnwindSafe for Cache<K>
where K: UnwindSafe,

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<T> Erased for T