Struct cache::Cache [−][src]
pub struct Cache<K> { /* fields omitted */ }
A thread-safe concurrent cache from key K
to arbitrarily typed values
Methods
impl<K: Hash + Eq> Cache<K>
[src]
impl<K: Hash + Eq> Cache<K>
pub fn new(num_pages: usize, page_size: usize) -> Self
[src]
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.
pub fn insert<V: 'static>(&self, key: K, val: V) -> Cached<V>
[src]
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.
pub fn get<'a, V: 'static>(&'a self, key: &K) -> Option<Cached<'a, V>>
[src]
pub fn get<'a, V: 'static>(&'a self, key: &K) -> Option<Cached<'a, V>>
Is this value in the cache?