mini_moka/
lib.rs

1#![warn(clippy::all)]
2#![warn(rust_2018_idioms)]
3#![deny(rustdoc::broken_intra_doc_links)]
4#![cfg_attr(docsrs, feature(doc_cfg))]
5
6//! Mini Moka is a fast, concurrent cache library for Rust. Mini Moka is a light
7//! edition of [Moka][moka-git].
8//!
9//! Mini Moka provides an in-memory concurrent cache implementation on top of hash
10//! map. It supports high expected concurrency of retrievals and updates.
11//!
12//! Mini Moka also provides an in-memory, non-thread-safe cache implementation for
13//! single thread applications.
14//!
15//! All cache implementations perform a best-effort bounding of the map using an
16//! entry replacement algorithm to determine which entries to evict when the capacity
17//! is exceeded.
18//!
19//! [moka-git]: https://github.com/moka-rs/moka
20//! [caffeine-git]: https://github.com/ben-manes/caffeine
21//!
22//! # Features
23//!
24//! - A thread-safe, highly concurrent in-memory cache implementation.
25//! - A cache can be bounded by one of the followings:
26//!     - The maximum number of entries.
27//!     - The total weighted size of entries. (Size aware eviction)
28//! - Maintains good hit rate by using entry replacement algorithms inspired by
29//!   [Caffeine][caffeine-git]:
30//!     - Admission to a cache is controlled by the Least Frequently Used (LFU) policy.
31//!     - Eviction from a cache is controlled by the Least Recently Used (LRU) policy.
32//! - Supports expiration policies:
33//!     - Time to live
34//!     - Time to idle
35//!
36//! # Examples
37//!
38//! See the following document:
39//!
40//! - A thread-safe, synchronous cache:
41//!     - [`sync::Cache`][sync-cache-struct]
42//! - A not thread-safe, blocking cache for single threaded applications:
43//!     - [`unsync::Cache`][unsync-cache-struct]
44//!
45//! [sync-cache-struct]: ./sync/struct.Cache.html
46//! [unsync-cache-struct]: ./unsync/struct.Cache.html
47//!
48//! # Minimum Supported Rust Versions
49//!
50//! This crate's minimum supported Rust versions (MSRV) are the followings:
51//!
52//! | Feature          | MSRV                       |
53//! |:-----------------|:--------------------------:|
54//! | default features | Rust 1.61.0 (May 19, 2022) |
55//!
56//! If only the default features are enabled, MSRV will be updated conservatively.
57//! When using other features, MSRV might be updated more frequently, up to the
58//! latest stable. In both cases, increasing MSRV is _not_ considered a
59//! semver-breaking change.
60
61pub(crate) mod common;
62pub(crate) mod policy;
63pub mod unsync;
64
65#[cfg(feature = "sync")]
66#[cfg_attr(docsrs, doc(cfg(feature = "sync")))]
67pub mod sync;
68
69pub use policy::Policy;
70
71#[cfg(test)]
72mod tests {
73    #[cfg(all(trybuild, feature = "sync"))]
74    #[test]
75    fn trybuild_sync() {
76        let t = trybuild::TestCases::new();
77        t.compile_fail("tests/compile_tests/sync/clone/*.rs");
78    }
79}