1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
//! Copyright (c) 2025-2026, Kirky.X
//!
//! MIT License
//!
//! oxcache - 高性能多层缓存库
//!
//! # Example
//!
//! ```rust,ignore
//! use oxcache::Cache;
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Serialize, Deserialize, Debug)]
//! struct User { id: u64, name: String }
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let cache: Cache<String, User> = Cache::builder().build().await?;
//! cache.set(&"user:1".to_string(), &User { id: 1, name: "Alice".into() }).await?;
//! let user = cache.get(&"user:1".to_string()).await?;
//! Ok(())
//! }
//! ```
//!
//! # Tiered Cache
//!
//! ```rust,ignore
//! use oxcache::cache::{ChainCache, ChainLink};
//! use oxcache::backend::MokaMemoryBackend;
//!
//! let l1 = MokaMemoryBackend::builder().capacity(10000).build();
//! let l2 = oxcache::backend::RedisBackend::new("redis://localhost:6379").await?;
//!
//! let chain = ChainCache::builder()
//! .link(ChainLink::from_backend(l1))
//! .link(ChainLink::from_backend(l2))
//! .enable_backfill()
//! .build();
//! ```
//!
//! # Sync API (0.3.0)
//!
//! Enable `sync_mode(true)` on the builder to get synchronous methods
//! (`get_sync` / `set_sync` / `set_with_ttl_sync` / `delete_sync` /
//! `exists_sync` / `get_or_sync` / `clear_sync`) alongside the async API.
//! Requires `multi_thread` tokio runtime for Moka-backed caches.
//!
//! ```rust,ignore
//! # #[tokio::main(flavor = "multi_thread")]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let cache: Cache<String, String> = Cache::builder().sync_mode(true).build().await?;
//! cache.set_sync(&"k".to_string(), &"v".to_string())?;
//! let v = cache.get_sync(&"k".to_string())?;
//! # Ok(()) }
//! ```
//!
//! # Bloom Filter (0.3.0)
//!
//! Enable the `bloom-filter` feature (not in `full`) for negative-query
//! filtering. [`BloomFilterBackend`] wraps any [`CacheBackend`] and skips
//! the inner backend on BF miss.
//!
//! ```rust,ignore
//! use oxcache::backend::MokaMemoryBackend;
//! use oxcache::features::bloom_filter::BloomFilterBackend;
//! let backend = BloomFilterBackend::new(MokaMemoryBackend::new());
//! ```
//!
//! # Universal per-entry TTL (0.3.0)
//!
//! All backends (Moka / DashMap / Redis / Mock / Chain / Bloom) honor
//! per-entry `set(key, value, Some(ttl))`. Moka uses the `moka::Expiry`
//! trait for real per-entry TTL (overriding the global TTL set on the
//! builder).
//!
//! # Features
//!
//! - `moka`: L1 memory cache (default in minimal/core/full)
//! - `redis`: L2 distributed cache
//! - `serialization`: JSON/Bincode/MessagePack/CBOR
//! - `metrics`: OpenTelemetry metrics
//! - `bloom-filter`: negative-query filtering (not in `full`)
//! - `full`: All features
// ============================================================================
// Feature Flags and Macros
// ============================================================================
/// 编译时特性依赖检查(支持 full 特性)
///
/// 注意:$required 应为特性名称字符串,而非 cfg 表达式。
///
/// # Example
///
/// ```rust,ignore
/// check_feature_dependence!("moka", "bloom-filter");
/// ```
///
/// 如果启用了 `bloom-filter` 但没有启用 `moka` 或 `full`,编译时会报错。
/// Initialize cache configuration from a function.
///
/// This macro generates code that calls the provided function to get configuration,
/// then initializes all caches from that configuration.
///
/// # Arguments
/// * `path` (optional) - Path to a TOML config file. If provided, uses confers_load.
/// * `config` (optional) - A function that returns `OxcacheConfig`.
///
/// Either `path` or `config` must be provided, but not both.
///
/// # Example
///
/// ```rust,ignore
/// #[oxcache::init_config]
/// fn load_config() -> oxcache::OxcacheConfig {
/// oxcache::oxcache_config()
/// .with_service("default", oxcache::ServiceConfig::two_level())
/// .build()
/// }
/// ```
// ============================================================================
// Core Modules (Always Available)
// ============================================================================
// Internal module for #[cached] macro support
// Must be `pub` (not `pub(crate)`) so the #[cached] macro can access
// __internal_get_cache from external crates. #[doc(hidden)] keeps it out of public docs.
// ============================================================================
// Primary Modules (Feature-Gated)
// ============================================================================
// Cache module (modern Cache<K,V> API)
// Backend module (L1/L2 cache implementation)
// Features module (optional capabilities)
// Infrastructure module (metrics, serialization, telemetry, etc.)
// Mock Module (For testing only)
// Registry module for #[cached] macro support
// Traits module: CacheKey
// Config module: confers-based configuration
// Utils module: key generation utilities
// Security module: Redis security validation
pub
// ============================================================================
// Public API Re-exports
// ============================================================================
// Re-export macros when the feature is enabled
pub use cached;
pub use ;
// Re-export internal functions needed by #[cached] macro at crate root
// The macro generates code calling ::oxcache::__internal_get_cache()
pub use crate__internal_get_cache;
// ============================================================================
// New API (Recommended)
// ============================================================================
// New API exports
pub use CacheBuilder;
pub use Cache;
// Re-exports from infra module
pub use ;
// Re-exports from security module (new brick architecture)
pub use crate;
// Public API re-exports (after features re-exports)
pub use ;
pub use UnifiedCache;
pub use CacheKey;
// Type-safe enum exports
pub use ;
// Key generator export
pub use crateKeyGenerator;
// Events module re-export
pub use ;
// Backend exports
pub use ;
pub use ;
// ============================================================================
// Factory Functions (Brick Architecture Standard)
// ============================================================================
/// oxcache 版本号
pub const VERSION: &str = env!;