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
//! # cache-mod
//!
//! HIGH-PERFORMANCE IN-PROCESS CACHING
//!
//! Multiple eviction policies (LRU, LFU, TinyLFU, TTL, size-bounded). Async-safe,
//! lock-minimized internals. Typed key-value API. No external store dependency.
//!
//! # Status
//!
//! **Stable.** As of 1.0.0 the public API surface is frozen under strict
//! SemVer — see `docs/STABILITY.md` for the full enumeration. Five
//! reference cache implementations sit behind a common [`Cache`] trait:
//! [`LruCache`] (Least-Recently-Used), [`LfuCache`] (Least-Frequently-Used),
//! [`TtlCache`] (Time-To-Live, lazy expiry), [`TinyLfuCache`] (Count-Min
//! Sketch admission filter + LRU main), and [`SizedCache`] (byte-bound
//! capacity). Internals are arena-backed and sharded for concurrent
//! throughput; the public surface does not depend on either choice and
//! will not change as those internals evolve in the 1.x line.
//!
//! # Guarantees
//!
//! - **No `unsafe`.** This crate contains zero `unsafe` blocks. Every cache
//! operation goes through safe abstractions only.
//! - **No `panic!`, no `unwrap`, no `expect`.** The library code never calls
//! any of these macros / methods on shipping paths. Where a non-panicking
//! `unreachable!()` appears, it documents an invariant the caller is
//! responsible for upholding inside `pub(crate)` arena helpers; every
//! public method is panic-free given valid arguments. `clippy::unwrap_used`
//! and `clippy::expect_used` are denied at the crate level.
//! - **No background threads.** Every cache type uses lazy bookkeeping —
//! eviction, expiry, and sketch aging run on the call-site thread that
//! triggered them. No `std::thread::spawn` happens inside the crate.
//! - **No required runtime.** The crate has no async runtime dependency.
//! `&self` everywhere lets you share cache instances across `.await`
//! points if you do use one.
//! - **Send + Sync.** Every cache type is `Send + Sync` when `K: Send + Sync`
//! and `V: Send + Sync`.
//!
//! # Quick start
//!
//! ```
//! use cache_mod::{Cache, LruCache};
//!
//! let cache: LruCache<&'static str, u32> = LruCache::new(64).expect("capacity > 0");
//!
//! cache.insert("requests", 1);
//! cache.insert("errors", 0);
//!
//! assert_eq!(cache.get(&"requests"), Some(1));
//! assert_eq!(cache.len(), 2);
//! ```
//!
//! # License
//!
//! Dual-licensed under Apache-2.0 OR MIT.
pub use Cache;
pub use CacheError;
pub use LfuCache;
pub use LruCache;
pub use SizedCache;
pub use TinyLfuCache;
pub use TtlCache;
/// Crate version string, populated by Cargo at build time.
pub const VERSION: &str = env!;