Skip to main content

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 defined: the [`Cache`] trait, the [`CacheError`]
11//! error type, and three reference cache implementations — [`LruCache`]
12//! (Least-Recently-Used, 0.2.0), [`LfuCache`] (Least-Frequently-Used, 0.3.0),
13//! and [`TtlCache`] (Time-To-Live with lazy expiry, 0.4.0). TinyLFU and
14//! size-bounded eviction policies land in 0.5.0. The API is not yet frozen —
15//! pin exact versions until 1.0.
16//!
17//! # Quick start
18//!
19//! ```
20//! use cache_mod::{Cache, LruCache};
21//!
22//! let cache: LruCache<&'static str, u32> = LruCache::new(64).expect("capacity > 0");
23//!
24//! cache.insert("requests", 1);
25//! cache.insert("errors", 0);
26//!
27//! assert_eq!(cache.get(&"requests"), Some(1));
28//! assert_eq!(cache.len(), 2);
29//! ```
30//!
31//! # License
32//!
33//! Dual-licensed under Apache-2.0 OR MIT.
34
35#![doc(html_root_url = "https://docs.rs/cache-mod")]
36#![cfg_attr(docsrs, feature(doc_cfg))]
37#![cfg_attr(not(feature = "std"), no_std)]
38#![deny(missing_docs)]
39#![deny(unsafe_op_in_unsafe_fn)]
40#![deny(unused_must_use)]
41#![deny(unused_results)]
42#![deny(clippy::unwrap_used)]
43#![deny(clippy::expect_used)]
44#![deny(clippy::todo)]
45#![deny(clippy::unimplemented)]
46#![deny(clippy::print_stdout)]
47#![deny(clippy::print_stderr)]
48#![deny(clippy::dbg_macro)]
49#![deny(clippy::undocumented_unsafe_blocks)]
50#![deny(clippy::missing_safety_doc)]
51
52mod cache;
53mod error;
54
55#[cfg(feature = "std")]
56mod lfu;
57#[cfg(feature = "std")]
58mod lru;
59#[cfg(feature = "std")]
60mod ttl;
61
62pub use cache::Cache;
63pub use error::CacheError;
64
65#[cfg(feature = "std")]
66pub use lfu::LfuCache;
67#[cfg(feature = "std")]
68pub use lru::LruCache;
69#[cfg(feature = "std")]
70pub use ttl::TtlCache;
71
72/// Crate version string, populated by Cargo at build time.
73pub const VERSION: &str = env!("CARGO_PKG_VERSION");