pub trait CacheExt: Cache {
// Provided methods
fn remember<'a, F, Fut>(
&'a self,
key: &'a str,
ttl: Duration,
compute: F,
) -> impl Future<Output = Result<Json>> + Send + 'a
where F: FnOnce() -> Fut + Send + 'a,
Fut: Future<Output = Result<Json>> + Send + 'a { ... }
fn remember_forever<'a, F, Fut>(
&'a self,
key: &'a str,
compute: F,
) -> impl Future<Output = Result<Json>> + Send + 'a
where F: FnOnce() -> Fut + Send + 'a,
Fut: Future<Output = Result<Json>> + Send + 'a { ... }
}Expand description
The conveniences that take a closure, and so cannot live on a dyn-compatible
trait. Blanket-implemented, including for dyn Cache.
Provided Methods§
Sourcefn remember<'a, F, Fut>(
&'a self,
key: &'a str,
ttl: Duration,
compute: F,
) -> impl Future<Output = Result<Json>> + Send + 'a
fn remember<'a, F, Fut>( &'a self, key: &'a str, ttl: Duration, compute: F, ) -> impl Future<Output = Result<Json>> + Send + 'a
Return the cached value, or compute it, store it for ttl, and return it.
The closure runs only on a miss. Note that two concurrent misses both compute: this is a cache, not a lock, and stampede protection would mean holding a lock across arbitrary user code.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".