pub struct CacheCoordinator { /* private fields */ }Expand description
Cache coordinator managing distributed and local caches
Provides automatic fallback from Redis (L2) to Memory (L1) on errors. Memory cache acts as both L1 fast-path and fallback for Redis failures.
Implementations§
Source§impl CacheCoordinator
impl CacheCoordinator
Sourcepub async fn from_config(config: &Config) -> Result<Self>
pub async fn from_config(config: &Config) -> Result<Self>
Create cache coordinator from config
Initializes both Redis and Memory caches based on configuration:
- If
redis_urlis set, initializes Redis (degraded mode if fails) - Always initializes Memory cache with configured size
§Errors
Returns error only if Memory cache creation fails (should never happen). Redis connection failures are logged but don’t fail initialization.
Sourcepub fn backend(&self) -> CacheBackend
pub fn backend(&self) -> CacheBackend
Get current cache backend mode
Sourcepub fn memory_stats(&self) -> (usize, usize, usize)
pub fn memory_stats(&self) -> (usize, usize, usize)
Get memory cache statistics
Returns (current_size, capacity, item_count)
Sourcepub fn clear_memory(&self)
pub fn clear_memory(&self)
Clear memory cache (for testing/admin operations)
Sourcepub fn redis(&self) -> Option<&Arc<RedisCache>>
pub fn redis(&self) -> Option<&Arc<RedisCache>>
Get Redis cache for advanced operations
Returns None if Redis is not configured or unavailable.
Trait Implementations§
Source§impl Cache for CacheCoordinator
impl Cache for CacheCoordinator
Source§fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Retrieve a value from cache by key Read more
Source§fn set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: &'life2 [u8],
ttl_seconds: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: &'life2 [u8],
ttl_seconds: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Store a value in cache with TTL Read more
Source§impl Clone for CacheCoordinator
impl Clone for CacheCoordinator
Source§fn clone(&self) -> CacheCoordinator
fn clone(&self) -> CacheCoordinator
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 Freeze for CacheCoordinator
impl !RefUnwindSafe for CacheCoordinator
impl Send for CacheCoordinator
impl Sync for CacheCoordinator
impl Unpin for CacheCoordinator
impl !UnwindSafe for CacheCoordinator
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