rok-cache
Cache abstraction for Axum with in-memory and Redis drivers. Provides
Cache::remember() for cache-aside, TTL control, and a response caching layer.
Installation
[]
= { = "0.1", = ["redis", "axum"] }
Quick Start
use ;
// In Axum state
let cache = memory; // in-process DashMap
let cache = redis;
// Get or compute
let user = cache
.remember
.await?;
// Manual operations
cache.put.await?;
let val: = cache.get.await?;
cache.forget.await?;
cache.flush.await?;
Features
| Feature | Description |
|---|---|
redis |
Redis driver via the redis crate |
axum |
CacheLayer middleware + CacheHandle extractor |
CacheLayer (response caching)
use CacheLayer;
let app = new
.route
.layer;
Namespaces
let user_cache = cache.namespace;
let session_cache = cache.namespace;
// Keys are automatically prefixed — no collisions