mini-moka

A fast, concurrent in-memory cache library for Rust, the light edition of Moka

Library
Cargo
v0.10.3
163 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
31 /100 Needs Attention
Development Activity 4
Maintenance 0
Community 44
Maturity 56
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
82 /100 Excellent
Architecture 86
Code Quality 85
Innovation 78
Learning Curve 80

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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers