Crema
A strongly consistent distributed cache built on Raft consensus and Moka local cache.
- Strong consistency — writes go through Raft consensus (linearizable)
- Multi-Raft sharding — horizontal scaling across independent Raft groups
- Gossip discovery — automatic peer discovery via memberlist (SWIM protocol)
- Pluggable storage — in-memory (default) or RocksDB for persistence
Quick Start
use ;
use Duration;
async
Running Examples
# Single node
# 3-node cluster (run each in a separate terminal)
RUST_LOG=info
RUST_LOG=info
RUST_LOG=info
# Multi-Raft mode
RUST_LOG=info
Cluster Setup
Add gossip-based discovery so nodes find each other automatically:
use ;
let memberlist_config = MemberlistConfig ;
let peers = vec!;
let discovery = new;
let config = new
.with_seed_nodes
.with_cluster_discovery;
let cache = new.await?;
Writes to any node are automatically forwarded to the Raft leader.
Multi-Raft Mode
For higher write throughput, shard the keyspace across multiple independent Raft groups:
use MultiRaftCacheConfig;
let config = new
.with_cluster_discovery
.with_multiraft_config;
Keys are routed via xxhash64(key) % num_shards. Each shard elects its own leader, distributing write load across the cluster.
Storage Backends
| Backend | Feature flag | Persistence | Recovery | Use case |
|---|---|---|---|---|
| Memory | (default) | No | Full replay | Dev, ephemeral caching |
| RocksDB | rocksdb |
Yes | Instant | Production |
use RaftStorageType;
let config = new
.with_raft_storage_type
.with_data_dir;
Consistency Model
| Operation | Guarantee |
|---|---|
put() / delete() |
Linearizable (Raft consensus) |
get() |
Eventually consistent (local read) |
consistent_get() |
Linearizable (leader roundtrip) |
Feature Flags
= "0.1.0" # default (memory + memberlist)
= { = "0.1.0", = ["rocksdb"] } # + persistent storage
= { = "0.1.0", = ["full"] } # everything
Development
License
Licensed under Apache 2.0 or MIT, at your option.