Struct simple_async_cache_rs::AsyncCacheStore [−][src]
pub struct AsyncCacheStore<K, V> { /* fields omitted */ }
Implementations
Construct a new AsyncCacheStore
instance.
Note: expire is the number of seconds for the cached value to expire.
Panic: If you set expire to less than 3 seconds. This limitaion exists because we expire value only every seconds, meaning there could be desynchronizations with a TTL lower than 3.
Fetch the key from the cache.
Returns an Arc
to the Mutex
for the key containing an Option.
The Mutex
prevents DogPile effect.
let cache = store.get("key_1".to_string()).await; let mut result = cache.lock().await; match &mut *result { Some(val) => { // You can get here the cached value for key_1 if it is already available. } None => { // There is no existing entry for key_1, you can do any expansive task to get the value and store it then. *result = Some("This is the content for key_1."); } }
Auto Trait Implementations
impl<K, V> !RefUnwindSafe for AsyncCacheStore<K, V>
impl<K, V> Send for AsyncCacheStore<K, V> where
K: Send,
V: Send,
impl<K, V> Sync for AsyncCacheStore<K, V> where
K: Send,
V: Send,
impl<K, V> Unpin for AsyncCacheStore<K, V> where
K: Unpin,
impl<K, V> !UnwindSafe for AsyncCacheStore<K, V>