Moka

Fast, concurrent in-memory caching library for Rust, inspired by Java's Caffeine

Library
Cargo
v0.12.16
2,690 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
66 /100 Good
Development Activity 56
Maintenance 56
Community 52
Maturity 60
Momentum 40

Technical Analysis

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

Moka is a fast, concurrent caching library for Rust inspired by the Caffeine library for Java. It provides both synchronous (thread-safe, shareable across OS threads) and asynchronous (futures-aware) cache implementations built on top of concurrent hash maps, with near-optimal hit ratios via a TinyLFU-based admission/eviction policy combining LFU admission with LRU eviction.

Caches can be bounded by entry count or total weighted size, support time-to-live and time-to-idle expiration plus per-entry variable expiration, and offer atomic per-key insertion (get_with), eviction listeners, and a lock-free concurrent iterator — the kind of feature depth needed by high-traffic production services (the crates.io registry itself uses Moka to maintain ~85% cache hit rates on its download endpoint).

What You Get

  • Thread-safe synchronous cache (moka::sync::Cache) shareable across OS threads via cheap cloning
  • An asynchronous, futures-aware cache (moka::future::Cache) for use under Tokio, async-std, or actix-rt
  • TinyLFU-inspired admission (LFU) and eviction (LRU) policy for near-optimal hit ratios
  • Size-aware eviction — bound a cache by entry count or total weighted size of entries
  • Time-to-live, time-to-idle, and per-entry variable expiration policies
  • Atomic per-key insertion methods (get_with, try_get_with) and an eviction listener callback

Common Use Cases

  • Reducing load on a backing database or API by caching frequently-accessed query results in-process
  • Building a high-throughput concurrent cache shared across many worker threads or async tasks
  • Caching with automatic expiration (TTL/TTI) for session data, rate-limit counters, or short-lived computed values
  • Embedding a cache in resource-constrained environments (e.g. home routers, embedded Linux) needing predictable memory bounds via size-aware eviction

Under The Hood

Architecture — Moka’s core lives in src/common (shared data structures and the TinyLFU-derived admission/eviction machinery), with parallel sync and future modules (src/sync, src/future) implementing the same conceptual cache over, respectively, a blocking/thread-safe API and an async/futures-aware API. A cht module implements the underlying concurrent hash table Moka builds its caches on top of, and notification/policy/ops modules handle eviction listener callbacks, cache-wide policy configuration, and cache operations respectively.

Tech Stack — Nearly pure Rust (99.6% of the codebase), feature-gated between sync and future cache variants so consumers only compile the concurrency model they need; the async cache integrates with any futures-aware runtime (Tokio, async-std, actix-rt) without hard-coding a single one. Moka explicitly does not support WebAssembly/WASI or no_std targets, focusing instead on full-std, multi-threaded server and embedded-Linux environments (tested down to 32-bit MIPS/ARMv5TE).

Code Quality — tests/ includes runtime-specific integration suites (runtime_tokio.rs, runtime_actix_rt2.rs, entry_api_sync.rs, entry_api_tokio.rs), stress tests for concurrent eviction correctness (eviction_stall_sync.rs, eviction_stall_future.rs, and_compute_with_race.rs), and a compile_tests directory verifying certain misuse patterns fail to compile. Codecov integration and an openspec/ directory of design specifications point to disciplined engineering practice; the README’s own comparison table against sibling projects (Mini Moka, Quick Cache) shows the maintainers are candid about Moka’s tradeoffs (larger dependency tree, more overhead) versus lighter-weight alternatives.

API Design — The sync::Cache/future::Cache split cleanly separates the two concurrency models while keeping a broadly consistent method surface (insert, get, get_with, invalidate) between them, and cache cloning is deliberately cheap (an Arc-based handle) so sharing across threads/tasks needs no extra wrapping. The v0.12 release introduced deliberate breaking changes (documented in a dedicated MIGRATION-GUIDE.md) to simplify internal behavior, which is a reasonable tradeoff for a caching library still refining its eviction internals.

Used by 8 apps in this directory

Dart
74%
AGPL 3.0

AppFlowy

AI Assistants · Collaboration · Productivity

76,967

The open-source AI workspace that puts your data, your rules — with local LLMs, CRDT collaboration, and full self-hosting built in.

View details
66
Repo Health
81
Technical
67
Dependency
Built with
Dart 74%
Rust 24%
Updated 1 weeks ago
TypeScript
64%
Apache 2.0

Laminar

AI Development · Monitoring

3,285

Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.

View details
85
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 64%
Rust 34%
Updated 5 days ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

39,975

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 4 days ago
Rust
72%
Apache 2.0

Rivet

AI Agents · Developer Tools

6,195

Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.

View details
86
Repo Health
81
Technical
64
Dependency
Built with
Rust 72%
TypeScript 25%
Updated 6 days ago
Rust
64%
Apache 2.0

Temps

Analytics · Devops · Monitoring

801

A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.

View details
81
Repo Health
86
Technical
70
Dependency
Built with
Rust 64%
TypeScript 34%
Updated 4 days ago
Rust
79%
Apache 2.0

TensorZero

Ab Testing Experimentation · AI Development · Monitoring

11,717

TensorZero unifies the LLM gateway, observability, evaluation, optimization, and experimentation stack behind a single OpenAI-compatible API, built in Rust for sub-millisecond p99 latency.

View details
53
Repo Health
87
Technical
69
Dependency
Built with
Rust 79%
TypeScript 15%
Updated 3 months ago
Rust
83%
AGPL 3.0

Vaultwarden

Password Manager · Security

68,240

Unofficial Bitwarden-compatible server in Rust — run the full Bitwarden ecosystem on a Raspberry Pi using every official client you already have, without the multi-container overhead.

View details
89
Repo Health
69
Technical
70
Dependency
Built with
Rust 83%
Updated 1 weeks ago
Rust
50%
Apache 2.0

Vibe Kanban

AI Agents · AI Code Assistants · Project Management

28,209

A kanban board for planning work and dispatching Claude Code, Codex, Gemini CLI, and eight other coding agents into isolated git worktrees, then reviewing and merging their diffs from one UI.

View details
75
Repo Health
75
Technical
64
Dependency
Built with
Rust 50%
TypeScript 46%
Updated 1 weeks ago

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