Skip to main content

Module cache

Module cache 

Source
Expand description

Application cache with a Laravel-style API: JSON values (serde), per-key TTL, atomic add and increment.

Stores: in-memory (default) and, with the db feature, the SeaORM table cache (self-created by Cache::ensure_tables, SQLite/PostgreSQL/MySQL). Expired entries are never returned.

use ryuk::cache::Cache;
use std::time::Duration;

let cache = Cache::memory();
cache.put("greeting", &"hello", Duration::from_secs(60)).await.unwrap();
assert_eq!(cache.get::<String>("greeting").await.unwrap().as_deref(), Some("hello"));
let n = cache.increment("hits", 1).await.unwrap();
assert_eq!(n, 1);
let v: u32 = cache.remember("answer", Duration::from_secs(60), || async { 42 }).await.unwrap();
assert_eq!(v, 42);

Modules§

entry
cache table.

Structs§

Cache
Cache handle; cheap to clone, share it through axum state.

Enums§

CacheError
Cache failure.