majordome-cache

Crates.iomajordome-cache
lib.rsmajordome-cache
version1.0.5
created_at2024-05-07 17:09:00.620012+00
updated_at2025-08-27 16:02:02.707753+00
descriptionA cache module for Majordome. Currently based on Moka.
homepage
repositoryhttps://github.com/merlleu/majordome
max_upload_size
id1232408
size30,765
Rémi Langdorph (merlleu)

documentation

README

majordome-cache

Overview

This crates lets you cache any date in memory with a simple API. To use it, simply inject MajordomeCache to your majordome App. Then you can simply get a MajordomeCacheGetter by calling MajordomeCache::key with the key you want to cache.

async fn do_expensive_operation(query: Q) -> Result<R, E> {}

let resp = app
        .get::<MajordomeCache>()?
        .key(&query)
        .ttl(60)
        .try_get_with(do_expensive_operation(query))
        .await?;

The past example will cache the result of do_expensive_operation for 60 seconds in memory, with a key based on the query. resp will have Arc type, so you can clone it and share it across threads for cheap.

Commit count: 71

cargo fmt