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")]
42#[cfg_attr(docsrs, doc(cfg(feature = "moka")))]
43pub mod moka_cache;
44
45#[cfg(feature = "redis")]
46#[cfg_attr(docsrs, doc(cfg(feature = "redis")))]
47pub mod redis_cache;
48
49// Optional backends (feature-gated)
50#[cfg(feature = "memcached")]
51#[cfg_attr(docsrs, doc(cfg(feature = "memcached")))]
52pub mod memcached_cache;
53
54#[cfg(feature = "quick_cache")]
55#[cfg_attr(docsrs, doc(cfg(feature = "quick_cache")))]
56pub mod quickcache_cache;
57
58// Re-export backend types
59pub use dashmap_cache::DashMapCache;
60
61#[cfg(feature = "moka")]
62#[cfg_attr(docsrs, doc(cfg(feature = "moka")))]
63pub use moka_cache::{MokaCache, MokaCacheConfig};
64
65#[cfg(feature = "redis")]
66#[cfg_attr(docsrs, doc(cfg(feature = "redis")))]
67pub use redis_cache::RedisCache;
68
69#[cfg(feature = "memcached")]
70#[cfg_attr(docsrs, doc(cfg(feature = "memcached")))]
71pub use memcached_cache::MemcachedCache;
72
73#[cfg(feature = "quick_cache")]
74#[cfg_attr(docsrs, doc(cfg(feature = "quick_cache")))]
75pub use quickcache_cache::QuickCacheBackend;
76
77// Type aliases for backward compatibility
78// These allow existing code to continue working without changes
79/// Type alias for `MokaCache` (default L1 backend)
80#[cfg(feature = "moka")]
81#[cfg_attr(docsrs, doc(cfg(feature = "moka")))]
82pub type L1Cache = MokaCache;
83
84/// Type alias for `RedisCache` (default L2 backend)
85#[cfg(feature = "redis")]
86#[cfg_attr(docsrs, doc(cfg(feature = "redis")))]
87pub type L2Cache = RedisCache;
88
89// Future backends will be added here with conditional compilation
90// based on feature flags:
91
92// #[cfg(feature = "backend-quickcache")]
93// pub mod quickcache_cache;
94// #[cfg(feature = "backend-quickcache")]
95// pub use quickcache_cache::QuickCacheBackend;
96
97// #[cfg(feature = "backend-dashmap")]
98// pub mod dashmap_cache;
99// #[cfg(feature = "backend-dashmap")]
100// pub use dashmap_cache::DashMapCache;
101
102// #[cfg(feature = "backend-rocksdb")]
103// pub mod rocksdb_cache;
104// #[cfg(feature = "backend-rocksdb")]
105// pub use rocksdb_cache::RocksDBCache;