ferro-cache

Crates.ioferro-cache
lib.rsferro-cache
version0.1.71
created_at2026-01-16 17:33:06.527279+00
updated_at2026-01-17 20:05:01.451562+00
descriptionCaching with tags for the Ferro framework
homepage
repositoryhttps://github.com/albertogferrario/ferro
max_upload_size
id2049010
size65,938
Alberto Giancarlo Ferrario (albertogferrario)

documentation

README

ferro-cache

Caching with tags for the Ferro framework.

Features

  • Multiple backends (Redis, in-memory)
  • Cache tags for bulk invalidation
  • Remember pattern for lazy caching
  • TTL (time-to-live) support

Usage

use ferro_cache::{Cache, CacheConfig};
use std::time::Duration;

// Create in-memory cache
let cache = Cache::memory();

// Store a value
cache.put("user:1", &user, Duration::from_secs(3600)).await?;

// Get a value
let user: Option<User> = cache.get("user:1").await?;

// Delete a value
cache.forget("user:1").await?;

Remember Pattern

Get from cache or compute and store:

let users = cache.remember("users:active", Duration::from_secs(3600), || async {
    User::where_active().all().await
}).await?;

Cache Tags

Tags allow bulk invalidation of related entries:

// Store with tags
cache.tags(&["users", "admins"])
    .put("user:1", &admin, Duration::from_secs(3600))
    .await?;

cache.tags(&["users"])
    .put("user:2", &regular_user, Duration::from_secs(3600))
    .await?;

// Flush all entries tagged with "users"
cache.tags(&["users"]).flush().await?;
// Both user:1 and user:2 are now invalidated

Redis Backend

Enable the redis-backend feature:

[dependencies]
ferro-cache = { version = "0.1", features = ["redis-backend"] }
let cache = Cache::redis("redis://localhost:6379").await?;

License

MIT

Commit count: 515

cargo fmt