Struct cache::multi::MultiCache
source · pub struct MultiCache { /* private fields */ }
Expand description
A cache with multiple providers.
Exposes a unified API for accessing an in-memory NamespaceCache
as well as persistent
cache Client
s.
Implementations§
source§impl MultiCache
impl MultiCache
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a MultiCache
with only in-memory providers.
sourcepub fn builder() -> MultiCacheBuilder
pub fn builder() -> MultiCacheBuilder
Creates a new MultiCacheBuilder
.
sourcepub fn generate<K: Serialize + Any + Send + Sync, V: Serialize + DeserializeOwned + Send + Sync + Any>(
&mut self,
namespace: impl Into<Namespace>,
key: K,
generate_fn: impl GenerateFn<K, V>
) -> CacheHandle<V>
pub fn generate<K: Serialize + Any + Send + Sync, V: Serialize + DeserializeOwned + Send + Sync + Any>( &mut self, namespace: impl Into<Namespace>, key: K, generate_fn: impl GenerateFn<K, V> ) -> CacheHandle<V>
Ensures that a value corresponding to key
is generated, using generate_fn
to generate it if it has not already been generated.
Returns a handle to the value. If the value is not yet generated, it is generated in the background.
See Client::generate
and NamespaceCache::generate
for related examples.
sourcepub fn generate_with_state<K: Serialize + Send + Sync + Any, S: Send + Sync + Any, V: Serialize + DeserializeOwned + Send + Sync + Any>(
&mut self,
namespace: impl Into<Namespace>,
key: K,
state: S,
generate_fn: impl GenerateWithStateFn<K, S, V>
) -> CacheHandle<V>
pub fn generate_with_state<K: Serialize + Send + Sync + Any, S: Send + Sync + Any, V: Serialize + DeserializeOwned + Send + Sync + Any>( &mut self, namespace: impl Into<Namespace>, key: K, state: S, generate_fn: impl GenerateWithStateFn<K, S, V> ) -> CacheHandle<V>
Ensures that a value corresponding to key
is generated, using generate_fn
to generate it if it has not already been generated.
Returns a handle to the value. If the value is not yet generated, it is generated in the background.
See Client::generate_with_state
and NamespaceCache::generate_with_state
for related examples.
sourcepub fn generate_result<K: Serialize + Any + Send + Sync, V: Serialize + DeserializeOwned + Send + Sync + Any, E: Send + Sync + Any>(
&mut self,
namespace: impl Into<Namespace>,
key: K,
generate_fn: impl GenerateResultFn<K, V, E>
) -> CacheHandle<Result<V, E>>
pub fn generate_result<K: Serialize + Any + Send + Sync, V: Serialize + DeserializeOwned + Send + Sync + Any, E: Send + Sync + Any>( &mut self, namespace: impl Into<Namespace>, key: K, generate_fn: impl GenerateResultFn<K, V, E> ) -> CacheHandle<Result<V, E>>
Ensures that a result corresponding to key
is generated, using generate_fn
to generate it if it has not already been generated.
Does not cache on failure as errors are not constrained to be serializable/deserializable.
As such, failures should happen quickly, or should be serializable and stored as part of
cached value using MultiCache::generate
.
Returns a handle to the value. If the value is not yet generated, it is generated
See Client::generate_result
and NamespaceCache::generate_result
for related examples.
sourcepub fn generate_result_with_state<K: Serialize + Send + Sync + Any, S: Send + Sync + Any, V: Serialize + DeserializeOwned + Send + Sync + Any, E: Send + Sync + Any>(
&mut self,
namespace: impl Into<Namespace>,
key: K,
state: S,
generate_fn: impl GenerateResultWithStateFn<K, S, V, E>
) -> CacheHandle<Result<V, E>>
pub fn generate_result_with_state<K: Serialize + Send + Sync + Any, S: Send + Sync + Any, V: Serialize + DeserializeOwned + Send + Sync + Any, E: Send + Sync + Any>( &mut self, namespace: impl Into<Namespace>, key: K, state: S, generate_fn: impl GenerateResultWithStateFn<K, S, V, E> ) -> CacheHandle<Result<V, E>>
Ensures that a value corresponding to key
is generated, using generate_fn
to generate it if it has not already been generated.
Does not cache on failure as errors are not constrained to be serializable/deserializable.
As such, failures should happen quickly, or should be serializable and stored as part of
cached value using MultiCache::generate_with_state
.
Returns a handle to the value. If the value is not yet generated, it is generated in the background.
See Client::generate_result_with_state
and
NamespaceCache::generate_result_with_state
for related examples.
sourcepub fn get<K: Cacheable>(
&mut self,
namespace: impl Into<Namespace>,
key: K
) -> CacheHandle<Result<K::Output, K::Error>>
pub fn get<K: Cacheable>( &mut self, namespace: impl Into<Namespace>, key: K ) -> CacheHandle<Result<K::Output, K::Error>>
Gets a handle to a cacheable object from the cache, generating the object in the background if needed.
Does not cache errors, so any errors thrown should be thrown quickly. Any errors that need
to be cached should be included in the cached output or should be cached using
MultiCache::get_with_err
.
See Client::get
and NamespaceCache::get
for related examples.
sourcepub fn get_with_err<E: Send + Sync + Serialize + DeserializeOwned + Any, K: Cacheable<Error = E>>(
&mut self,
namespace: impl Into<Namespace>,
key: K
) -> CacheHandle<Result<K::Output, K::Error>>
pub fn get_with_err<E: Send + Sync + Serialize + DeserializeOwned + Any, K: Cacheable<Error = E>>( &mut self, namespace: impl Into<Namespace>, key: K ) -> CacheHandle<Result<K::Output, K::Error>>
Gets a handle to a cacheable object from the cache, caching failures as well.
Generates the object in the background if needed.
See Client::get_with_err
and NamespaceCache::get_with_err
for related examples.
sourcepub fn get_with_state<S: Send + Sync + Any, K: CacheableWithState<S>>(
&mut self,
namespace: impl Into<Namespace>,
key: K,
state: S
) -> CacheHandle<Result<K::Output, K::Error>>
pub fn get_with_state<S: Send + Sync + Any, K: CacheableWithState<S>>( &mut self, namespace: impl Into<Namespace>, key: K, state: S ) -> CacheHandle<Result<K::Output, K::Error>>
Gets a handle to a cacheable object from the cache, generating the object in the background if needed.
Does not cache errors, so any errors thrown should be thrown quickly. Any errors that need
to be cached should be included in the cached output or should be cached using
MultiCache::get_with_state_and_err
.
See Client::get_with_state
and NamespaceCache::get_with_state
for related examples.
sourcepub fn get_with_state_and_err<S: Send + Sync + Any, E: Send + Sync + Serialize + DeserializeOwned + Any, K: CacheableWithState<S, Error = E>>(
&mut self,
namespace: impl Into<Namespace>,
key: K,
state: S
) -> CacheHandle<Result<K::Output, K::Error>>
pub fn get_with_state_and_err<S: Send + Sync + Any, E: Send + Sync + Serialize + DeserializeOwned + Any, K: CacheableWithState<S, Error = E>>( &mut self, namespace: impl Into<Namespace>, key: K, state: S ) -> CacheHandle<Result<K::Output, K::Error>>
Gets a handle to a cacheable object from the cache, caching failures as well.
Generates the object in the background if needed.
See MultiCache::get_with_err
and MultiCache::get_with_state
for related examples.
Trait Implementations§
source§impl Clone for MultiCache
impl Clone for MultiCache
source§fn clone(&self) -> MultiCache
fn clone(&self) -> MultiCache
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for MultiCache
impl Debug for MultiCache
source§impl Default for MultiCache
impl Default for MultiCache
source§fn default() -> MultiCache
fn default() -> MultiCache
Auto Trait Implementations§
impl !RefUnwindSafe for MultiCache
impl Send for MultiCache
impl Sync for MultiCache
impl Unpin for MultiCache
impl !UnwindSafe for MultiCache
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request