multi_tier_cache/backends/mod.rs
1//! Cache Backend Implementations
2//!
3//! This module contains all cache backend implementations for the multi-tier cache system.
4//!
5//! # Available Backends
6//!
7//! ## In-Memory (L1 Tier)
8//! - **Moka** - High-performance concurrent cache with automatic eviction (default L1)
9//! - **`DashMap`** - Simple concurrent HashMap-based cache
10//! - **`QuickCache`** - Lightweight, optimized for maximum performance (feature: `backend-quickcache`)
11//!
12//! ## Distributed (L2 Tier)
13//! - **Redis** - Industry-standard distributed cache with persistence (default L2)
14//! - **Memcached** - Lightweight distributed cache (feature: `backend-memcached`)
15//!
16//! ## On-Disk (L3/L4 Tier)
17//! - **`RocksDB`** - Embedded persistent key-value store (coming soon)
18//!
19//! # Usage
20//!
21//! ```rust,no_run
22//! use multi_tier_cache::backends::{MokaCache, MokaCacheConfig, RedisCache};
23//!
24//! # async fn example() -> anyhow::Result<()> {
25//! // Explicit backend selection
26//! let moka = MokaCache::new(MokaCacheConfig::default())?;
27//! let redis = RedisCache::new().await?;
28//!
29//! // Or use type aliases for backward compatibility
30//! use multi_tier_cache::backends::{L1Cache, L2Cache};
31//! let l1 = L1Cache::new(MokaCacheConfig::default())?; // MokaCache
32//! let l2 = L2Cache::new().await?; // RedisCache
33//! # Ok(())
34//! # }
35//! ```
36
37// Core backends (now optional via features)
38// Core backends
39pub mod dashmap_cache;
40
41#[cfg(feature = "moka")]
42pub mod moka_cache;
43
44#[cfg(feature = "redis")]
45pub mod redis_cache;
46
47// Optional backends (feature-gated)
48#[cfg(feature = "memcached")]
49pub mod memcached_cache;
50
51#[cfg(feature = "quick_cache")]
52pub mod quickcache_cache;
53
54// Re-export backend types
55pub use dashmap_cache::DashMapCache;
56
57#[cfg(feature = "moka")]
58pub use moka_cache::{MokaCache, MokaCacheConfig};
59
60#[cfg(feature = "redis")]
61pub use redis_cache::RedisCache;
62
63#[cfg(feature = "memcached")]
64pub use memcached_cache::MemcachedCache;
65
66#[cfg(feature = "quick_cache")]
67pub use quickcache_cache::QuickCacheBackend;
68
69// Type aliases for backward compatibility
70// These allow existing code to continue working without changes
71/// Type alias for `MokaCache` (default L1 backend)
72#[cfg(feature = "moka")]
73pub type L1Cache = MokaCache;
74
75/// Type alias for `RedisCache` (default L2 backend)
76#[cfg(feature = "redis")]
77pub type L2Cache = RedisCache;
78
79// Future backends will be added here with conditional compilation
80// based on feature flags:
81
82// #[cfg(feature = "backend-quickcache")]
83// pub mod quickcache_cache;
84// #[cfg(feature = "backend-quickcache")]
85// pub use quickcache_cache::QuickCacheBackend;
86
87// #[cfg(feature = "backend-dashmap")]
88// pub mod dashmap_cache;
89// #[cfg(feature = "backend-dashmap")]
90// pub use dashmap_cache::DashMapCache;
91
92// #[cfg(feature = "backend-rocksdb")]
93// pub mod rocksdb_cache;
94// #[cfg(feature = "backend-rocksdb")]
95// pub use rocksdb_cache::RocksDBCache;