Umbral
Back to plugin directory
UC

Umbral Cache

Official by Umbral contributors

ambient cache, response caching, Redis/in-memory backends

official stable

About

The fastest query is the one you don't run twice. Umbral Cache installs a process-wide in-memory cache as an ambient handle — reach for it from any handler to memoise an expensive aggregate, a rendered fragment, or a third-party API response. When a whole page is safe to share, an opt-in cache_page layer caches the entire response. No client to configure, no keys to manage in dev.

Install

cargo add umbral-cache

Wire it up

use umbral::prelude::*;
use umbral_cache::{CachePlugin, Cache};

let app = App::builder()
    .database("default", pool)
    .plugin(CachePlugin::new(Cache::memory()))
    .build()?;

Target: memoise an expensive dashboard query

Read from the ambient handle, compute on a miss, store for next time.

use umbral_cache::ambient;

async fn stats() -> Stats {
    if let Some(hit) = ambient().get::<Stats>("dashboard:stats").await {
        return hit;
    }
    let fresh = compute_expensive_stats().await;   // the slow path, once
    ambient().set("dashboard:stats", &fresh, /* ttl */ 60).await;
    fresh
}

What you get

  • Process-wide in-memory cache as an ambient handle
  • Reach it from any handler — no wiring through call stacks
  • Opt-in cache_page layer for whole-response caching
  • A pluggable backend so a shared store can slot in later

Usage

Install `CachePlugin::new(Cache::memory())` to register the ambient cache handle, then reach it from any handler with `umbral_cache::ambient()`. Layer `cache_page` only on responses that are safe to share (anonymous, non-per-user).

plugin setup
cargo add umbral-cache

Feature tracker

Per-feature shipping status, recorded in the directory.

7 of 7 shipped
Ambient cache handle shipped Stable

Install one cache and read it from any handler.

Typed get/set helpers shipped Stable

Serde-backed values with per-key TTL support.

Memory backend shipped Stable

In-process cache for development and single-process apps.

SQLite backend shipped Beta

Persistent local cache backed by an explicit SQLite pool.

Redis backend usable Beta

Feature-gated Redis backend with connection-manager reconnects.

cache_page layer shipped Beta

Caches eligible GET/HEAD responses and skips private/no-store.

Response headers shipped Beta

Optional compression, Cache-Control, and Vary headers.

Compatibility

Declared support per Umbral version and database backend.

No compatibility rows declared yet.

Community notes

0 notes in the discussion thread.

No notes yet. Be the first to share how this plugin works for you.

Reported issues

Bugs and abuse reports filed against this plugin.

Report an issue

No open issues

No issues have been reported against this plugin. Track upstream bugs on the maintainer's tracker, or report a directory problem to the Umbral team.