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, RedisCache};
23//!
24//! # async fn example() -> anyhow::Result<()> {
25//! // Explicit backend selection
26//! let moka = MokaCache::new()?;
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()?; // MokaCache
32//! let l2 = L2Cache::new().await?; // RedisCache
33//! # Ok(())
34//! # }
35//! ```
36
37// Core backends (always available)
38pub mod dashmap_cache;
39pub mod moka_cache;
40pub mod redis_cache;
41
42// Optional backends (feature-gated)
43#[cfg(feature = "backend-memcached")]
44pub mod memcached_cache;
45
46#[cfg(feature = "backend-quickcache")]
47pub mod quickcache_cache;
48
49// Re-export backend types
50pub use dashmap_cache::DashMapCache;
51pub use moka_cache::MokaCache;
52pub use redis_cache::RedisCache;
53
54#[cfg(feature = "backend-memcached")]
55pub use memcached_cache::MemcachedCache;
56
57#[cfg(feature = "backend-quickcache")]
58pub use quickcache_cache::QuickCacheBackend;
59
60// Type aliases for backward compatibility
61// These allow existing code to continue working without changes
62/// Type alias for `MokaCache` (default L1 backend)
63///
64/// **Note**: This is a type alias for backward compatibility.
65/// Consider using `MokaCache` directly in new code.
66pub type L1Cache = MokaCache;
67
68/// Type alias for `RedisCache` (default L2 backend)
69///
70/// **Note**: This is a type alias for backward compatibility.
71/// Consider using `RedisCache` directly in new code.
72pub type L2Cache = RedisCache;
73
74// Future backends will be added here with conditional compilation
75// based on feature flags:
76
77// #[cfg(feature = "backend-quickcache")]
78// pub mod quickcache_cache;
79// #[cfg(feature = "backend-quickcache")]
80// pub use quickcache_cache::QuickCacheBackend;
81
82// #[cfg(feature = "backend-dashmap")]
83// pub mod dashmap_cache;
84// #[cfg(feature = "backend-dashmap")]
85// pub use dashmap_cache::DashMapCache;
86
87// #[cfg(feature = "backend-rocksdb")]
88// pub mod rocksdb_cache;
89// #[cfg(feature = "backend-rocksdb")]
90// pub use rocksdb_cache::RocksDBCache;