cache_mod/lib.rs
1//! # cache-mod
2//!
3//! HIGH-PERFORMANCE IN-PROCESS CACHING
4//!
5//! Multiple eviction policies (LRU, LFU, TinyLFU, TTL, size-bounded). Async-safe,
6//! lock-minimized internals. Typed key-value API. No external store dependency.
7//!
8//! # Status
9//!
10//! The public API surface is feature-complete: the [`Cache`] trait, the
11//! [`CacheError`] error type, and five reference cache implementations —
12//! [`LruCache`] (Least-Recently-Used), [`LfuCache`] (Least-Frequently-Used),
13//! [`TtlCache`] (Time-To-Live, lazy expiry), [`TinyLfuCache`] (Count-Min Sketch
14//! admission filter + LRU main), and [`SizedCache`] (byte-bound capacity).
15//! Lock-free, arena-backed rewrites land in 0.6.0 without changing this
16//! public surface. The API is not yet frozen — pin exact versions until 1.0.
17//!
18//! # Quick start
19//!
20//! ```
21//! use cache_mod::{Cache, LruCache};
22//!
23//! let cache: LruCache<&'static str, u32> = LruCache::new(64).expect("capacity > 0");
24//!
25//! cache.insert("requests", 1);
26//! cache.insert("errors", 0);
27//!
28//! assert_eq!(cache.get(&"requests"), Some(1));
29//! assert_eq!(cache.len(), 2);
30//! ```
31//!
32//! # License
33//!
34//! Dual-licensed under Apache-2.0 OR MIT.
35
36#![doc(html_root_url = "https://docs.rs/cache-mod")]
37#![cfg_attr(docsrs, feature(doc_cfg))]
38#![cfg_attr(not(feature = "std"), no_std)]
39#![deny(missing_docs)]
40#![deny(unsafe_op_in_unsafe_fn)]
41#![deny(unused_must_use)]
42#![deny(unused_results)]
43#![deny(clippy::unwrap_used)]
44#![deny(clippy::expect_used)]
45#![deny(clippy::todo)]
46#![deny(clippy::unimplemented)]
47#![deny(clippy::print_stdout)]
48#![deny(clippy::print_stderr)]
49#![deny(clippy::dbg_macro)]
50#![deny(clippy::undocumented_unsafe_blocks)]
51#![deny(clippy::missing_safety_doc)]
52
53mod cache;
54mod error;
55
56#[cfg(feature = "std")]
57mod lfu;
58#[cfg(feature = "std")]
59mod lru;
60#[cfg(feature = "std")]
61mod sharding;
62#[cfg(feature = "std")]
63mod sized;
64#[cfg(feature = "std")]
65mod tinylfu;
66#[cfg(feature = "std")]
67mod ttl;
68#[cfg(feature = "std")]
69mod util;
70
71pub use cache::Cache;
72pub use error::CacheError;
73
74#[cfg(feature = "std")]
75pub use lfu::LfuCache;
76#[cfg(feature = "std")]
77pub use lru::LruCache;
78#[cfg(feature = "std")]
79pub use sized::SizedCache;
80#[cfg(feature = "std")]
81pub use tinylfu::TinyLfuCache;
82#[cfg(feature = "std")]
83pub use ttl::TtlCache;
84
85/// Crate version string, populated by Cargo at build time.
86pub const VERSION: &str = env!("CARGO_PKG_VERSION");