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
//! # unistore-cache
//!
//! 内存缓存能力 - UniStore 能力生态的一部分。
//!
//! ## 功能特性
//!
//! - **LRU 淘汰**: 基于最近最少使用策略自动淘汰
//! - **TTL 支持**: 可设置条目过期时间
//! - **线程安全**: 使用 parking_lot 高性能锁
//! - **统计信息**: 命中率、大小等缓存统计
//! - **泛型支持**: 支持任意 Key-Value 类型
//!
//! ## 快速开始
//!
//! ```rust
//! use unistore_cache::{Cache, CacheConfig};
//! use std::time::Duration;
//!
//! // 创建缓存
//! let cache: Cache<String, String> = Cache::new(CacheConfig::default()
//! .max_capacity(1000)
//! .default_ttl(Duration::from_secs(300)));
//!
//! // 存取数据
//! cache.insert("key1".to_string(), "value1".to_string());
//! let value = cache.get(&"key1".to_string());
//! assert_eq!(value, Some("value1".to_string()));
//! ```
//!
//! ## 自定义 TTL
//!
//! ```rust
//! use unistore_cache::{Cache, CacheConfig};
//! use std::time::Duration;
//!
//! let cache: Cache<&str, i32> = Cache::with_defaults();
//!
//! // 使用默认 TTL
//! cache.insert("key1", 100);
//!
//! // 使用自定义 TTL
//! cache.insert_with_ttl("key2", 200, Some(Duration::from_secs(60)));
//!
//! // 永不过期
//! cache.insert_with_ttl("key3", 300, None);
//! ```
//!
//! ## Get or Insert
//!
//! ```rust
//! use unistore_cache::Cache;
//!
//! let cache: Cache<&str, String> = Cache::with_defaults();
//!
//! // 如果不存在则计算并插入
//! let value = cache.get_or_insert_with("expensive_key", || {
//! // 昂贵的计算...
//! "computed_value".to_string()
//! });
//! ```
//!
//! ## 统计信息
//!
//! ```rust
//! use unistore_cache::Cache;
//!
//! let cache: Cache<&str, i32> = Cache::with_defaults();
//! cache.insert("key1", 42);
//! cache.get(&"key1");
//! cache.get(&"key2"); // miss
//!
//! let stats = cache.stats();
//! println!("命中率: {:.2}%", stats.hit_rate() * 100.0);
//! ```
// === 内部模块 ===
// === 对外接口(SDK)===
pub use Cache;
pub use CacheConfig;
pub use CacheEntry;
pub use CacheError;
pub use ;