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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.