pub enum Cache<K, V, S = RandomState>{
Fifo(Arc<GenericCache<K, V, SanityEviction<Fifo<(K, V)>>, SanityIndexer<HashTableIndexer<K, FifoHandle<(K, V)>>>, S>>),
Lru(Arc<GenericCache<K, V, SanityEviction<Lru<(K, V)>>, SanityIndexer<HashTableIndexer<K, LruHandle<(K, V)>>>, S>>),
Lfu(Arc<GenericCache<K, V, SanityEviction<Lfu<(K, V)>>, SanityIndexer<HashTableIndexer<K, LfuHandle<(K, V)>>>, S>>),
S3Fifo(Arc<GenericCache<K, V, SanityEviction<S3Fifo<(K, V)>>, SanityIndexer<HashTableIndexer<K, S3FifoHandle<(K, V)>>>, S>>),
}Expand description
In-memory cache with plug-and-play algorithms.
Variants§
Fifo(Arc<GenericCache<K, V, SanityEviction<Fifo<(K, V)>>, SanityIndexer<HashTableIndexer<K, FifoHandle<(K, V)>>>, S>>)
In-memory FIFO cache.
Lru(Arc<GenericCache<K, V, SanityEviction<Lru<(K, V)>>, SanityIndexer<HashTableIndexer<K, LruHandle<(K, V)>>>, S>>)
In-memory LRU cache.
Lfu(Arc<GenericCache<K, V, SanityEviction<Lfu<(K, V)>>, SanityIndexer<HashTableIndexer<K, LfuHandle<(K, V)>>>, S>>)
In-memory LFU cache.
S3Fifo(Arc<GenericCache<K, V, SanityEviction<S3Fifo<(K, V)>>, SanityIndexer<HashTableIndexer<K, S3FifoHandle<(K, V)>>>, S>>)
In-memory S3FIFO cache.
Implementations§
source§impl<K, V, S> Cache<K, V, S>
impl<K, V, S> Cache<K, V, S>
sourcepub fn insert(&self, key: K, value: V) -> CacheEntry<K, V, S>
pub fn insert(&self, key: K, value: V) -> CacheEntry<K, V, S>
Insert cache entry to the in-memory cache.
sourcepub fn insert_with_context(
&self,
key: K,
value: V,
context: CacheContext,
) -> CacheEntry<K, V, S>
pub fn insert_with_context( &self, key: K, value: V, context: CacheContext, ) -> CacheEntry<K, V, S>
Insert cache entry with cache context to the in-memory cache.
sourcepub fn deposit(&self, key: K, value: V) -> CacheEntry<K, V, S>
pub fn deposit(&self, key: K, value: V) -> CacheEntry<K, V, S>
Temporarily insert cache entry to the in-memory cache.
The entry will be removed as soon as the returned entry is dropped.
The entry will become a normal entry after it is accessed.
sourcepub fn deposit_with_context(
&self,
key: K,
value: V,
context: CacheContext,
) -> CacheEntry<K, V, S>
pub fn deposit_with_context( &self, key: K, value: V, context: CacheContext, ) -> CacheEntry<K, V, S>
Temporarily insert cache entry with cache context to the in-memory cache.
The entry will be removed as soon as the returned entry is dropped.
The entry will become a normal entry after it is accessed.
sourcepub fn remove<Q>(&self, key: &Q) -> Option<CacheEntry<K, V, S>>
pub fn remove<Q>(&self, key: &Q) -> Option<CacheEntry<K, V, S>>
Remove a cached entry with the given key from the in-memory cache.
sourcepub fn get<Q>(&self, key: &Q) -> Option<CacheEntry<K, V, S>>
pub fn get<Q>(&self, key: &Q) -> Option<CacheEntry<K, V, S>>
Get cached entry with the given key from the in-memory cache.
sourcepub fn contains<Q>(&self, key: &Q) -> bool
pub fn contains<Q>(&self, key: &Q) -> bool
Check if the in-memory cache contains a cached entry with the given key.
source§impl<K, V, S> Cache<K, V, S>
impl<K, V, S> Cache<K, V, S>
sourcepub fn fetch<F, FU, ER>(&self, key: K, fetch: F) -> Fetch<K, V, ER, S> ⓘ
pub fn fetch<F, FU, ER>(&self, key: K, fetch: F) -> Fetch<K, V, ER, S> ⓘ
Get the cached entry with the given key from the in-memory cache.
Use fetch to fetch the cache value from the remote storage on cache miss.
The concurrent fetch requests will be deduplicated.
sourcepub fn fetch_with_context<F, FU, ER>(
&self,
key: K,
context: CacheContext,
fetch: F,
) -> Fetch<K, V, ER, S> ⓘ
pub fn fetch_with_context<F, FU, ER>( &self, key: K, context: CacheContext, fetch: F, ) -> Fetch<K, V, ER, S> ⓘ
Get the cached entry with the given key and context from the in-memory cache.
Use fetch to fetch the cache value from the remote storage on cache miss.
The concurrent fetch requests will be deduplicated.
Trait Implementations§
Auto Trait Implementations§
impl<K, V, S> Freeze for Cache<K, V, S>
impl<K, V, S = RandomState> !RefUnwindSafe for Cache<K, V, S>
impl<K, V, S> Send for Cache<K, V, S>
impl<K, V, S> Sync for Cache<K, V, S>
impl<K, V, S> Unpin for Cache<K, V, S>
impl<K, V, S = RandomState> !UnwindSafe for Cache<K, V, S>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more