# 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
```toml
[dependencies]
rok-cache = { version = "0.1", features = ["redis", "axum"] }
```
## Quick Start
```rust
use rok_cache::{Cache, CacheHandle};
// In Axum state
let cache = Cache::memory(); // in-process DashMap
let cache = Cache::redis("redis://127.0.0.1:6379");
// Get or compute
let user = cache
.remember("user:42", 300, || async {
User::find(42, &pool).await
})
.await?;
// Manual operations
cache.put("key", &value, 60).await?;
let val: Option<MyType> = cache.get("key").await?;
cache.forget("key").await?;
cache.flush().await?;
```
## Features
| `redis` | Redis driver via the `redis` crate |
| `axum` | `CacheLayer` middleware + `CacheHandle` extractor |
## CacheLayer (response caching)
```rust
use rok_cache::CacheLayer;
let app = Router::new()
.route("/products", get(products_index))
.layer(CacheLayer::new(cache.clone()).ttl(300));
```
## Namespaces
```rust
let user_cache = cache.namespace("users");
let session_cache = cache.namespace("sessions");
// Keys are automatically prefixed — no collisions
```