Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Local Cache API

This page summarizes the main local cache methods. Use it as a map, not as a replacement for Rustdoc.

Reads And Writes

MethodPurpose
getReturn Ok(Some(T)) for a usable value, or Ok(None) when missing or expired.
putStore a typed value with CacheOptions.
contains_keyCheck whether a key currently maps to a usable value. Expired entries are removed and reported as absent.
removeLocal-cache spelling for key invalidation.

Loaders

MethodPurpose
get_or_loadRun a fallible loader on miss, store the loaded value, and share same-key concurrent loads.
get_or_load_with_refreshLike get_or_load, with explicit refresh-ahead and stale behavior.
get_or_insert_withShort spelling for infallible async loaders.
try_get_or_insert_withFallible-loader spelling; equivalent in intent to get_or_load.

Concurrent same-key loader calls share one in-flight load. Cache hits bypass single-flight entirely.

Keys And Tags

Type or methodPurpose
CacheKeyBuilderBuild escaped :-separated keys from segments.
TagSetCollect reusable invalidation tags.
CacheOptions::tagAttach one tag.
CacheOptions::tagsAttach several tags.
CacheOptions::tag_setAttach a prebuilt TagSet.
invalidate_keyRemove one key.
invalidate_tagRemove all entries currently associated with the tag.
flushRemove all local entries.

If a tag is invalidated while a tagged loader is still running, HydraCache skips storing that stale loader result. Callers after the invalidation start or join a fresh load instead of joining the stale one.

Typed Views

typed::<T>("namespace") creates a TypedCache<T> namespaced view over the same runtime.

It keeps shared storage, stats, single-flight, tags, and invalidation behavior, while making repeated typed operations less noisy.

Diagnostics

MethodPurpose
statsReturn lightweight counters for hits, misses, loads, single-flight joins, invalidations, stale load discards, events, and transport diagnostics.
diagnostics().awaitReturn stats plus local backend approximate entry count for smoke checks.
subscribe and tag/key filtered variantsObserve cache behavior through event streams.
callback listenersRegister callback-style mutation/access listeners while the returned handle is alive.

Use diagnostics to prove basic cache behavior locally: the first call should miss and load, and the second same-key call should hit.

For exact signatures, see API Links.