pub struct CacheSystem {
pub cache_manager: Arc<CacheManager>,
pub l1_cache: Arc<L1Cache>,
pub l2_cache: Arc<L2Cache>,
}Expand description
Main entry point for the Multi-Tier Cache system
Provides unified access to L1 (Moka) and L2 (Redis) caches with automatic failover, promotion, and stampede protection.
§Example
use multi_tier_cache::CacheSystem;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cache = CacheSystem::new().await?;
// Use cache_manager for all operations
let manager = cache.cache_manager();
Ok(())
}Fields§
§cache_manager: Arc<CacheManager>Unified cache manager (primary interface)
l1_cache: Arc<L1Cache>L1 Cache (in-memory, Moka)
l2_cache: Arc<L2Cache>L2 Cache (distributed, Redis)
Implementations§
Source§impl CacheSystem
impl CacheSystem
Sourcepub async fn new() -> Result<Self>
pub async fn new() -> Result<Self>
Create new cache system with default configuration
§Configuration
Redis connection is configured via REDIS_URL environment variable.
Default: redis://127.0.0.1:6379
§Example
use multi_tier_cache::CacheSystem;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Set environment variable (optional)
std::env::set_var("REDIS_URL", "redis://localhost:6379");
let cache = CacheSystem::new().await?;
Ok(())
}Sourcepub async fn with_redis_url(redis_url: &str) -> Result<Self>
pub async fn with_redis_url(redis_url: &str) -> Result<Self>
Create cache system with custom Redis URL
§Arguments
redis_url- Redis connection string (e.g., “redis://localhost:6379”)
§Example
use multi_tier_cache::CacheSystem;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cache = CacheSystem::with_redis_url("redis://custom:6379").await?;
Ok(())
}Sourcepub async fn health_check(&self) -> bool
pub async fn health_check(&self) -> bool
Perform health check on all cache tiers
Returns true if at least L1 is operational.
L2 failure is tolerated (graceful degradation).
§Example
use multi_tier_cache::CacheSystem;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cache = CacheSystem::new().await?;
if cache.health_check().await {
println!("Cache system healthy");
}
Ok(())
}Sourcepub fn cache_manager(&self) -> &Arc<CacheManager>
pub fn cache_manager(&self) -> &Arc<CacheManager>
Get reference to cache manager (primary interface)
Use this for all cache operations: get, set, streams, etc.
Trait Implementations§
Source§impl Clone for CacheSystem
impl Clone for CacheSystem
Source§fn clone(&self) -> CacheSystem
fn clone(&self) -> CacheSystem
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 CacheSystem
impl !RefUnwindSafe for CacheSystem
impl Send for CacheSystem
impl Sync for CacheSystem
impl Unpin for CacheSystem
impl !UnwindSafe for CacheSystem
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