Expand description
User-facing HydraCache local runtime.
v0 is intentionally local-only: no SQLx adapter, no distributed coordination, and no cluster membership. The goal is a small async cache with TTL, tags, local single-flight, and pleasant loader ergonomics.
§Quick start
use std::time::Duration;
use hydracache::{CacheOptions, HydraCache};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
struct User {
id: u64,
name: String,
}
let cache = HydraCache::local()
.default_ttl(Duration::from_secs(300))
.max_capacity(10_000)
.build();
let user = cache
.get_or_insert_with("user:42", CacheOptions::new().tag("user:42"), || async {
User {
id: 42,
name: "Ada".to_owned(),
}
})
.await?;
assert_eq!(user.id, 42);
cache.invalidate_tag("user:42").await?;§Typed local cache
use hydracache::{CacheOptions, HydraCache};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
struct User {
id: u64,
name: String,
}
let cache = HydraCache::local().build();
let users = cache.typed::<User>("users");
users
.put(
"42",
User {
id: 42,
name: "Ada".to_owned(),
},
CacheOptions::new(),
)
.await?;
let cached = users.get("42").await?;
assert_eq!(cached.map(|user| user.id), Some(42));Structs§
- Cache
Key - A logical cache key.
- Cache
KeyBuilder - Builder for cache keys made of escaped
:-separated segments. - Cache
Options - Per-entry cache behavior.
- Cache
Stats - Snapshot of lightweight cache counters.
- Hydra
Cache - Local async cache runtime.
- Hydra
Cache Builder - Builder for a local
HydraCacheinstance. - Options
- Per-entry cache behavior.
- Postcard
Codec - Default compact binary codec for v0.
- Stats
- Snapshot of lightweight cache counters.
- TagSet
- A reusable set of cache invalidation tags.
- Typed
Cache - A typed, namespaced view over a
HydraCache.
Enums§
- Cache
Error - Errors returned by HydraCache.
Type Aliases§
- Cache
Result - HydraCache result type.