pub enum Cache<K, V, S = DefaultHasher, P = CacheProperties>{
Fifo(Arc<RawCache<Fifo<K, V, P>, S>>),
Lru(Arc<RawCache<Lru<K, V, P>, S>>),
Lfu(Arc<RawCache<Lfu<K, V, P>, S>>),
S3Fifo(Arc<RawCache<S3Fifo<K, V, P>, S>>),
Sieve(Arc<RawCache<Sieve<K, V, P>, S>>),
}Expand description
In-memory cache with plug-and-play algorithms.
Variants§
Fifo(Arc<RawCache<Fifo<K, V, P>, S>>)
In-memory FIFO cache.
Lru(Arc<RawCache<Lru<K, V, P>, S>>)
In-memory LRU cache.
Lfu(Arc<RawCache<Lfu<K, V, P>, S>>)
In-memory LFU cache.
S3Fifo(Arc<RawCache<S3Fifo<K, V, P>, S>>)
In-memory S3FIFO cache.
Sieve(Arc<RawCache<Sieve<K, V, P>, S>>)
In-memory Sieve cache.
Implementations§
Source§impl<K, V> Cache<K, V, DefaultHasher, CacheProperties>
impl<K, V> Cache<K, V, DefaultHasher, CacheProperties>
Sourcepub fn builder(capacity: usize) -> CacheBuilder<K, V, DefaultHasher>
pub fn builder(capacity: usize) -> CacheBuilder<K, V, DefaultHasher>
Create a new in-memory cache builder with capacity.
Source§impl<K, V, S, P> Cache<K, V, S, P>
impl<K, V, S, P> Cache<K, V, S, P>
Sourcepub fn resize(&self, capacity: usize) -> Result<()>
pub fn resize(&self, capacity: usize) -> Result<()>
Update capacity and evict overflowed entries.
Sourcepub fn insert(&self, key: K, value: V) -> CacheEntry<K, V, S, P>
pub fn insert(&self, key: K, value: V) -> CacheEntry<K, V, S, P>
Insert cache entry to the in-memory cache.
Sourcepub fn insert_with_properties(
&self,
key: K,
value: V,
properties: P,
) -> CacheEntry<K, V, S, P>
pub fn insert_with_properties( &self, key: K, value: V, properties: P, ) -> CacheEntry<K, V, S, P>
Insert cache entry to the in-memory cache with properties.
Sourcepub fn remove<Q>(&self, key: &Q) -> Option<CacheEntry<K, V, S, P>>
pub fn remove<Q>(&self, key: &Q) -> Option<CacheEntry<K, V, S, P>>
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, P>>
pub fn get<Q>(&self, key: &Q) -> Option<CacheEntry<K, V, S, P>>
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.
Sourcepub fn touch<Q>(&self, key: &Q) -> bool
pub fn touch<Q>(&self, key: &Q) -> bool
Access the cached entry with the given key but don’t return.
Note: This method can be used to update the cache eviction information and order based on the algorithm.
Sourcepub fn hash_builder(&self) -> &Arc<S>
pub fn hash_builder(&self) -> &Arc<S>
Get the hash builder of the in-memory cache.
Sourcepub fn evict_all(&self)
pub fn evict_all(&self)
Evict all entries from the in-memory cache.
Instead of Cache::clear, Cache::evict_all will send the evicted pipe to the pipe.
It is useful when the cache is used as a hybrid cache.
Source§impl<K, V, S, P> Cache<K, V, S, P>
impl<K, V, S, P> Cache<K, V, S, P>
Sourcepub fn fetch<F, FU, ER>(&self, key: K, fetch: F) -> Fetch<K, V, ER, S, P> ⓘ
pub fn fetch<F, FU, ER>(&self, key: K, fetch: F) -> Fetch<K, V, ER, S, P> ⓘ
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_properties<F, FU, ER>(
&self,
key: K,
properties: P,
fetch: F,
) -> Fetch<K, V, ER, S, P> ⓘ
pub fn fetch_with_properties<F, FU, ER>( &self, key: K, properties: P, fetch: F, ) -> Fetch<K, V, ER, S, P> ⓘ
Get the cached entry with the given key and properties 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, P> Freeze for Cache<K, V, S, P>
impl<K, V, S = BuildHasherDefault<Hasher>, P = CacheProperties> !RefUnwindSafe for Cache<K, V, S, P>
impl<K, V, S, P> Send for Cache<K, V, S, P>
impl<K, V, S, P> Sync for Cache<K, V, S, P>
impl<K, V, S, P> Unpin for Cache<K, V, S, P>
impl<K, V, S = BuildHasherDefault<Hasher>, P = CacheProperties> !UnwindSafe for Cache<K, V, S, P>
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§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