pub struct CacheManager<B, S = JsonSerializer, M = NoopMetrics>{ /* private fields */ }Expand description
High-level cache manager with pluggable serialization and metrics
Generic over:
B: The cache backend (Memory, Redis, MultiTier)S: The serializer (JSON, MessagePack, Bincode)M: The metrics collector
Implementations§
Source§impl<B: CacheBackend + DependencyBackend> CacheManager<B, JsonSerializer, NoopMetrics>
impl<B: CacheBackend + DependencyBackend> CacheManager<B, JsonSerializer, NoopMetrics>
Sourcepub fn new(backend: B) -> Self
pub fn new(backend: B) -> Self
Create a new CacheManager with default JSON serializer and no metrics
Sourcepub fn with_config(backend: B, config: CacheManagerConfig) -> Self
pub fn with_config(backend: B, config: CacheManagerConfig) -> Self
Create with custom config
Source§impl<B, S, M> CacheManager<B, S, M>
impl<B, S, M> CacheManager<B, S, M>
Sourcepub fn with_serializer_and_metrics(
backend: B,
serializer: S,
metrics: M,
config: CacheManagerConfig,
) -> Self
pub fn with_serializer_and_metrics( backend: B, serializer: S, metrics: M, config: CacheManagerConfig, ) -> Self
Create a CacheManager with custom serializer and metrics
Sourcepub fn group(&self, namespace: impl Into<String>) -> CacheGroup<'_, B, S, M>
pub fn group(&self, namespace: impl Into<String>) -> CacheGroup<'_, B, S, M>
Create a namespaced cache group
Sourcepub async fn get<T>(&self, key: impl CacheKey) -> Result<CacheResult<T>>where
T: DeserializeOwned,
pub async fn get<T>(&self, key: impl CacheKey) -> Result<CacheResult<T>>where
T: DeserializeOwned,
Get a value from cache
Sourcepub async fn set<T>(
&self,
key: impl CacheKey,
value: T,
options: impl Into<CacheOptions>,
) -> Result<()>where
T: Serialize,
pub async fn set<T>(
&self,
key: impl CacheKey,
value: T,
options: impl Into<CacheOptions>,
) -> Result<()>where
T: Serialize,
Set a value in cache
Sourcepub async fn get_or_compute<T, F, Fut>(
&self,
key: impl CacheKey,
computer: F,
options: Option<CacheOptions>,
) -> Result<CacheResult<T>>
pub async fn get_or_compute<T, F, Fut>( &self, key: impl CacheKey, computer: F, options: Option<CacheOptions>, ) -> Result<CacheResult<T>>
Get a value from cache, or compute it if missing (coalesced)
Sourcepub async fn delete(&self, key: impl CacheKey) -> Result<bool>
pub async fn delete(&self, key: impl CacheKey) -> Result<bool>
Delete a key from cache (with cascade invalidation)
Sourcepub async fn invalidate(&self, key: impl CacheKey) -> Result<u64>
pub async fn invalidate(&self, key: impl CacheKey) -> Result<u64>
Invalidate a key and all its dependents (cascade invalidation)
Returns the number of entries invalidated
Sourcepub async fn stats(&self) -> Result<CacheStats>
pub async fn stats(&self) -> Result<CacheStats>
Get cache statistics
Source§impl<B, S, M> CacheManager<B, S, M>
impl<B, S, M> CacheManager<B, S, M>
Trait Implementations§
Source§impl<B, S, M> CacheManagerReadThroughExt<B, S, M> for CacheManager<B, S, M>
impl<B, S, M> CacheManagerReadThroughExt<B, S, M> for CacheManager<B, S, M>
fn read_through<K, V, L>( self, loader: L, options: CacheOptions, ) -> ReadThroughCache<B, S, M, K, V, L>
Source§impl<B, S, M> Clone for CacheManager<B, S, M>
impl<B, S, M> Clone for CacheManager<B, S, M>
Auto Trait Implementations§
impl<B, S, M> Freeze for CacheManager<B, S, M>
impl<B, S = JsonSerializer, M = NoopMetrics> !RefUnwindSafe for CacheManager<B, S, M>
impl<B, S, M> Send for CacheManager<B, S, M>
impl<B, S, M> Sync for CacheManager<B, S, M>
impl<B, S, M> Unpin for CacheManager<B, S, M>
impl<B, S = JsonSerializer, M = NoopMetrics> !UnwindSafe for CacheManager<B, S, M>
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
Mutably borrows from an owned value. Read more