Struct crude_cache::CrudeCache
source · pub struct CrudeCache { /* private fields */ }Implementations§
source§impl CrudeCache
impl CrudeCache
sourcepub fn new(num_shards: usize) -> Self
pub fn new(num_shards: usize) -> Self
num_shards- Determines how many internal Shards (HashMaps) cache has.default()uses 64.
sourcepub async fn force_insert<V>(
&self,
k: impl Into<String>,
v: V,
duration: Duration
)where
V: 'static + Sync + Send + Clone,
pub async fn force_insert<V>( &self, k: impl Into<String>, v: V, duration: Duration )where V: 'static + Sync + Send + Clone,
Inserts new value regardless of existing items expiration. Causes writelock for the shard
sourcepub async fn get<V: 'static + Clone>(&self, key: &str) -> Option<V>
pub async fn get<V: 'static + Clone>(&self, key: &str) -> Option<V>
Gets the item by its key. If the value does not exist or it has expired, returns None.
Panics
Panics if value of the cached type is not V.
sourcepub async fn get_or_else_update<V, F, Fut>(
&self,
key: &str,
expiration: Duration,
get: F
) -> Vwhere
V: 'static + Clone + Sync + Send,
F: Fn() -> Fut,
Fut: Future<Output = V>,
pub async fn get_or_else_update<V, F, Fut>( &self, key: &str, expiration: Duration, get: F ) -> Vwhere V: 'static + Clone + Sync + Send, F: Fn() -> Fut, Fut: Future<Output = V>,
Gets the item by its key. If the value does not exist or it has expired,
new value by calling the provided get Fn.
Panics
Causes panic if value of the cached type is not V.
Trait Implementations§
source§impl Clone for CrudeCache
impl Clone for CrudeCache
source§fn clone(&self) -> CrudeCache
fn clone(&self) -> CrudeCache
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for CrudeCache
impl Send for CrudeCache
impl Sync for CrudeCache
impl Unpin for CrudeCache
impl !UnwindSafe for CrudeCache
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
Mutably borrows from an owned value. Read more