HydraCache
HydraCache is a Rust-native local async cache that is designed to grow toward database result caching and distributed synchronization later.
Status
HydraCache is in early development. The current implementation targets the first local-cache release.
v0 Scope
The first version includes:
- local async cache runtime
HydraCache::local()buildergetputget_or_load- local single-flight miss deduplication
contains_key- per-entry TTL and default TTL
- tag-aware invalidation
- key invalidation
removeas a local-cache alias for key invalidationflushpostcardcodec overBytes- lightweight stats
- Moka-backed local storage
Out of scope for v0:
- SQLx adapter
- proc macros
- distributed invalidation
- cluster roles
- generation counters
- persistence
Example
use Duration;
use ;
use ;
async
# async
API Notes
get returns Ok(None) when the key is missing or expired.
get_or_load runs the loader on a miss and stores the loaded value with the provided CacheOptions.
Concurrent get_or_load calls for the same missing key share one loader execution. Cache hits bypass single-flight entirely.
contains_key checks whether a key currently maps to a usable value. Expired entries are removed and reported as absent.
remove and invalidate_key both remove one key. remove is the shorter local-cache spelling; invalidate_key is kept for consistency with tag invalidation.
invalidate_tag removes all entries currently associated with the tag.
Use CacheOptions::tag("users") for one tag and CacheOptions::tags(["users", "user:42"]) for multiple tags.
stats returns lightweight counters for hits, misses, loads, invalidations, and evictions. v0 does not wire backend eviction listeners yet, so evictions remains zero.
Release Plan
The v0 release plan is maintained here:
Workspace
crates/hydracache-core- core public types, codec, options, errors, statscrates/hydracache- user-facing local cache runtimecrates/hydracache-macros- future macro ergonomicscrates/hydracache-sqlx- future SQLx-first adapter layer