mini-moka
A fast, concurrent in-memory cache library for Rust, the light edition of Moka
Repository Health
Technical Analysis
mini-moka is a fast, concurrent in-memory caching library for Rust and a lighter edition of the full Moka crate. It provides thread-safe cache implementations built on top of hash maps that support full concurrency of retrievals and a high expected concurrency for updates, plus a non-thread-safe variant for single-threaded applications.
Caches perform best-effort bounding using an entry-replacement algorithm inspired by Caffeine: admission is governed by a Least Frequently Used (TinyLFU) policy and eviction by Least Recently Used, which keeps a near-optimal hit ratio. It also supports size-aware eviction via a weigher closure and time-to-live and time-to-idle expiration policies.
What You Get
- A thread-safe, highly concurrent in-memory Cache in the sync module
- A non-thread-safe cache for single-threaded applications in the unsync module
- TinyLFU admission and LRU eviction for near-optimal hit ratios
- Size-aware eviction via a user-provided weigher closure
- Time-to-live and time-to-idle expiration policies via a builder
Common Use Cases
- Caching expensive computation or query results in a concurrent Rust service
- Bounding memory use with size-aware eviction for variably sized values
- Expiring cached entries automatically with TTL or TTI policies
- Sharing a single cache cheaply across many worker threads
Under The Hood
Architecture - The crate is split into a sync module (a concurrent cache built on dashmap with a base_cache, builder, iterator, and map-reference types) and an unsync module for single-threaded use, sharing a common policy layer that implements the TinyLFU admission and LRU eviction algorithms inspired by Caffeine. The sync Cache is cheaply cloneable because clones share the same underlying state. Tech Stack - Pure Rust (MSRV 1.76) built on crossbeam-channel and crossbeam-utils for concurrency, dashmap for the concurrent map, smallvec, tagptr, and triomphe for low-overhead data structures, with dashmap as an optional-but-default dependency. Code Quality - The repository includes a test suite plus compile-fail tests, README doc tests run via skeptic, a documented rolling MSRV policy, a CHANGELOG, and CI, indicating a mature and carefully maintained codebase. API Design - The public API mirrors the ergonomics of the full Moka crate: construct a Cache directly or via Cache::builder() to configure capacity, weigher, and expiration, then use insert/get/invalidate, with get returning an owned clone of the value to keep concurrency sound.