pub struct CacheManager<B: CacheBackend> { /* private fields */ }Expand description
The main cache manager that coordinates caching operations.
This is the primary entry point for the caching system. It wraps any
CacheBackend implementation and provides a unified API.
Implementations§
Source§impl<B: CacheBackend> CacheManager<B>
impl<B: CacheBackend> CacheManager<B>
Sourcepub fn with_options(backend: B, options: CacheOptions) -> Self
pub fn with_options(backend: B, options: CacheOptions) -> Self
Create with custom default options.
Sourcepub fn metrics(&self) -> &CacheMetrics
pub fn metrics(&self) -> &CacheMetrics
Get the metrics collector.
Sourcepub async fn get<T>(&self, key: &CacheKey) -> CacheResult<Option<T>>where
T: DeserializeOwned,
pub async fn get<T>(&self, key: &CacheKey) -> CacheResult<Option<T>>where
T: DeserializeOwned,
Get a value from the cache.
Sourcepub async fn set<T>(
&self,
key: &CacheKey,
value: &T,
options: Option<&CacheOptions>,
) -> CacheResult<()>
pub async fn set<T>( &self, key: &CacheKey, value: &T, options: Option<&CacheOptions>, ) -> CacheResult<()>
Set a value in the cache.
Sourcepub async fn get_or_set<T, F, Fut>(
&self,
key: &CacheKey,
f: F,
options: Option<&CacheOptions>,
) -> CacheResult<T>where
T: Serialize + DeserializeOwned + Sync,
F: FnOnce() -> Fut,
Fut: Future<Output = CacheResult<T>>,
pub async fn get_or_set<T, F, Fut>(
&self,
key: &CacheKey,
f: F,
options: Option<&CacheOptions>,
) -> CacheResult<T>where
T: Serialize + DeserializeOwned + Sync,
F: FnOnce() -> Fut,
Fut: Future<Output = CacheResult<T>>,
Get or compute a value.
If the value exists in cache, returns it. Otherwise, calls the provided function to compute the value, caches it, and returns it.
Sourcepub async fn delete(&self, key: &CacheKey) -> CacheResult<bool>
pub async fn delete(&self, key: &CacheKey) -> CacheResult<bool>
Delete a value from the cache.
Sourcepub async fn exists(&self, key: &CacheKey) -> CacheResult<bool>
pub async fn exists(&self, key: &CacheKey) -> CacheResult<bool>
Check if a key exists in the cache.
Sourcepub async fn invalidate_pattern(&self, pattern: &KeyPattern) -> CacheResult<u64>
pub async fn invalidate_pattern(&self, pattern: &KeyPattern) -> CacheResult<u64>
Invalidate cache entries by pattern.
Sourcepub async fn invalidate_entity(&self, entity: &str) -> CacheResult<u64>
pub async fn invalidate_entity(&self, entity: &str) -> CacheResult<u64>
Invalidate all entries for an entity type.
Sourcepub async fn invalidate_record<I: Display>(
&self,
entity: &str,
id: I,
) -> CacheResult<u64>
pub async fn invalidate_record<I: Display>( &self, entity: &str, id: I, ) -> CacheResult<u64>
Invalidate a specific record.
Invalidate entries by tags.
Sourcepub async fn clear(&self) -> CacheResult<()>
pub async fn clear(&self) -> CacheResult<()>
Clear all entries from the cache.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Get cache statistics.
Trait Implementations§
Source§impl<B: Clone + CacheBackend> Clone for CacheManager<B>
impl<B: Clone + CacheBackend> Clone for CacheManager<B>
Source§fn clone(&self) -> CacheManager<B>
fn clone(&self) -> CacheManager<B>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<B> Freeze for CacheManager<B>
impl<B> RefUnwindSafe for CacheManager<B>where
B: RefUnwindSafe,
impl<B> Send for CacheManager<B>
impl<B> Sync for CacheManager<B>
impl<B> Unpin for CacheManager<B>
impl<B> UnwindSafe for CacheManager<B>where
B: RefUnwindSafe,
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