One cache API, six stores.

Get, put, remember and atomic locks over memory, Redis, Redis Cluster, Memcached, DynamoDB or Cloudflare Workers KV.

What you get

  • remember and remember_forever for the pattern nearly every cache use is.
  • Typed reads and writes through CacheExt: get_json::<Post>, put_json.
  • Atomic locks — the scheduler’s overlap protection uses them.
  • A store failure the cache works around is a CacheFailed event, not a silent miss.
  • Honest limit: Workers KV is eventually consistent and has no atomic add.

In the docs

src/app/http/controllers/stats_controller.rs
use rainier_framework::cache::CacheExt;
use rainier_framework::facades::Cache;

pub async fn totals() -> Result<Response> {
    let posts = resolve::<PostRepository>()?;

    // Computed once, then read from the store for five minutes.
    let totals = Cache::instance()
        .remember("stats.totals", Some(Duration::from_secs(300)), || async {
            posts.totals().await
        })
        .await?;

    Ok(Response::json(&totals))
}

Up close

Select an image to see it full size.

remember() runs the slow call once and serves the cached value after that; a failure is never cached.
Every cache call is a span with the store and whether it hit, with no application code.
All features

Type to search 2.0.0 docs.