Strongly consistent distributed cache with Raft consensus.
This crate provides an embedded distributed cache that uses:
- Moka for high-performance local caching with automatic TTL/eviction
- raft-rs for strong consistency via Raft consensus
- Two-tier membership for safe cluster management
Features
- Strong consistency for writes via Raft consensus
- Fast local reads from Moka cache
- Automatic TTL and TinyLFU eviction
- Two-tier cluster membership (discovery + manual Raft control)
- Pre-validation to ensure state machine apply never fails
Example
use ;
use Duration;
async
Architecture
┌─────────────────────────────────────────────┐
│ Application Layer │
└─────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ DistributedCache API │
│ • get(key) -> Option<Value> │
│ • put(key, value) -> Result<()> │
│ • delete(key) -> Result<()> │
└─────────────────────────────────────────────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
┌─────────┐ ┌──────────┐ ┌─────────┐
│ Cluster │ │ Raft │ │ Moka │
│Membership│ │Consensus │ │ Cache │
└─────────┘ └──────────┘ └─────────┘
Consistency Model
- Writes: Strongly consistent via Raft (linearizable)
- Reads: Locally consistent (may be stale on followers)
- Leader reads: Strongly consistent if reading from leader
Checkpointing
The cache supports periodic checkpointing for fast recovery:
use ;
let config = new
.with_log_threshold
.with_compression;
// Snapshots are automatically created based on configured triggers