rok-cache 0.1.0

Cache façade for the rok ecosystem — Memory/Redis drivers, Cache::get/set/remember
Documentation

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

[dependencies]
rok-cache = { version = "0.1", features = ["redis", "axum"] }

Quick Start

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

Feature Description
redis Redis driver via the redis crate
axum CacheLayer middleware + CacheHandle extractor

CacheLayer (response caching)

use rok_cache::CacheLayer;

let app = Router::new()
    .route("/products", get(products_index))
    .layer(CacheLayer::new(cache.clone()).ttl(300));

Namespaces

let user_cache = cache.namespace("users");
let session_cache = cache.namespace("sessions");
// Keys are automatically prefixed — no collisions