pub struct Cache { /* private fields */ }
Expand description
A cache with APIs for in-memory and persistent caching.
Implementations§
source§impl Cache
impl Cache
sourcepub fn new(cache: MultiCache) -> Self
pub fn new(cache: MultiCache) -> Self
Creates a new Cache
with the provided MultiCache
configuration.
sourcepub fn get<K: Cacheable>(
&self,
namespace: impl Into<String>,
key: K
) -> CacheHandle<Result<K::Output, K::Error>>
pub fn get<K: Cacheable>( &self, namespace: impl Into<String>, 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.
If configured, persists data to disk.
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
Cache::get_with_err
.
sourcepub fn get_with_err<E: Send + Sync + Serialize + DeserializeOwned + Any, K: Cacheable<Error = E>>(
&self,
namespace: impl Into<String>,
key: K
) -> CacheHandle<Result<K::Output, K::Error>>
pub fn get_with_err<E: Send + Sync + Serialize + DeserializeOwned + Any, K: Cacheable<Error = E>>( &self, namespace: impl Into<String>, 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 and persists data to disk according to configuration.
sourcepub fn get_with_state<S: Send + Sync + Any, K: CacheableWithState<S>>(
&self,
namespace: impl Into<String>,
key: K,
state: S
) -> CacheHandle<Result<K::Output, K::Error>>
pub fn get_with_state<S: Send + Sync + Any, K: CacheableWithState<S>>( &self, namespace: impl Into<String>, 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.
If configured, persists data to disk.
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
Cache::get_with_state_and_err
.
sourcepub fn get_with_state_and_err<S: Send + Sync + Any, E: Send + Sync + Serialize + DeserializeOwned + Any, K: CacheableWithState<S, Error = E>>(
&self,
namespace: impl Into<String>,
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>>( &self, namespace: impl Into<String>, 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 and persists data to disk according to configuration.
See Cache::get_with_err
and Cache::get_with_state
for related examples.
sourcepub fn type_get<K: Cacheable>(
&self,
key: K
) -> CacheHandle<Result<K::Output, K::Error>>
pub fn type_get<K: Cacheable>( &self, 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.
Only caches data in memory.
sourcepub fn type_get_with_state<S: Send + Sync + Any, K: CacheableWithState<S>>(
&self,
key: K,
state: S
) -> CacheHandle<Result<K::Output, K::Error>>
pub fn type_get_with_state<S: Send + Sync + Any, K: CacheableWithState<S>>( &self, 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.
Only caches data in memory.
Note: The state is not used to determine whether the object should be regenerated. As such, it should not impact the output of this function but rather should only be used to store collateral or reuse computation from other function calls.
However, the entries generated with different state types are not interchangeable. That is,
getting the same key with different states will regenerate the key several times, once for
each state type S
.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnwindSafe for Cache
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
source§impl<T, U> CustomHardwareType<Flipped<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
impl<T, U> CustomHardwareType<Flipped<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
source§fn from_layout_type(other: &Flipped<T>) -> U
fn from_layout_type(other: &Flipped<T>) -> U
source§impl<T, U> CustomHardwareType<InOut<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
impl<T, U> CustomHardwareType<InOut<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
source§fn from_layout_type(other: &InOut<T>) -> U
fn from_layout_type(other: &InOut<T>) -> U
source§impl<T, U> CustomHardwareType<Input<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
impl<T, U> CustomHardwareType<Input<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
source§fn from_layout_type(other: &Input<T>) -> U
fn from_layout_type(other: &Input<T>) -> U
source§impl<T, U> CustomHardwareType<Output<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
impl<T, U> CustomHardwareType<Output<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
source§fn from_layout_type(other: &Output<T>) -> U
fn from_layout_type(other: &Output<T>) -> U
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for 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