| Crates.io | ferro-cache |
| lib.rs | ferro-cache |
| version | 0.1.71 |
| created_at | 2026-01-16 17:33:06.527279+00 |
| updated_at | 2026-01-17 20:05:01.451562+00 |
| description | Caching with tags for the Ferro framework |
| homepage | |
| repository | https://github.com/albertogferrario/ferro |
| max_upload_size | |
| id | 2049010 |
| size | 65,938 |
Caching with tags for the Ferro framework.
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?;
Get from cache or compute and store:
let users = cache.remember("users:active", Duration::from_secs(3600), || async {
User::where_active().all().await
}).await?;
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", ®ular_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
Enable the redis-backend feature:
[dependencies]
ferro-cache = { version = "0.1", features = ["redis-backend"] }
let cache = Cache::redis("redis://localhost:6379").await?;
MIT