Typed Cache
Use a typed cache view when several call sites share one value type and one domain namespace.
let cache = HydraCache::local().build();
let profiles = cache.typed::<Profile>("profiles");
profiles
.put(
"42",
Profile {
id: 42,
display_name: "Ada".to_owned(),
},
CacheOptions::new()
.ttl(Duration::from_secs(60))
.tag_set(TagSet::new().entity("profile", 42).tag("profiles")),
)
.await?;
let profile = profiles.get("42").await?;
assert_eq!(profile.as_ref().map(|profile| profile.id), Some(42));
cache.invalidate_tag("profile:42").await?;
assert_eq!(profiles.get("42").await?, None);
The typed view does not create separate storage. It is a namespaced view over the same HydraCache runtime, so stats, events, invalidation safety, and single-flight behavior remain shared.
The namespace prefixes keys. In the example, the typed key 42 is stored as profiles:42 in the underlying cache. Use namespaces that match domain boundaries rather than module names.
Typed views are most useful when they remove repeated annotations without hiding cache semantics. Keep keys, tags, and TTLs visible at the call site.