v0.14.0
HydraCache 0.14.0 Release Notes
HydraCache 0.14.0 adds cacheable!(...), the first local-cache macro for
ordinary expensive async work. This release keeps function caching separate from
database result caching: no SQLx, entity, collection, or repository concepts are
required.
What's New
- Added
cacheable!(...)inhydracache-macros. - Re-exported
cacheable!fromhydracache. - Required explicit
cache,key, andloadoptions. - Supported repeated
tagoptions. - Supported one TTL option:
ttl = Durationorttl_secs = u64. - Kept the generated path on top of
HydraCache::get_or_load, so existing
single-flight, TTL, tag invalidation, codec, and stats behavior still applies.
Example
use hydracache::{cacheable, HydraCache};
# async fn example() -> hydracache::CacheResult<()> {
let cache = HydraCache::local().build();
let value = cacheable!(
cache = cache,
key = "expensive:42",
tag = "expensive",
ttl_secs = 60,
load = || async { Ok::<_, std::io::Error>(42_u64) },
)
.await?;
assert_eq!(value, 42);
# Ok(())
# }Why It Matters
cacheable! gives application code a shorter spelling for ordinary async
function/result caching while preserving the main HydraCache design rule: cache
keys, tags, TTLs, and loaders remain explicit and visible at the call site.
This is intentionally different from the database adapter API:
- Use
cacheable!for expensive calculations, HTTP calls, filesystem reads, or
non-database service calls. - Use
hydracache-dborhydracache-sqlxfor database/repository result
caching with entity and collection invalidation semantics.
Known Boundaries
cacheable!is explicit-only: callers provide the cache, key, tags, TTL, and
loader.- It is not an attribute macro yet and does not rewrite function definitions.
- It does not derive keys or tags from function arguments.
- It does not replace
HydraCache::get_or_load; it is a compact spelling on
top of the same runtime path and bounds.
Compatibility
This release is additive. Existing HydraCache, TypedCache, DbCache,
QueryCachePolicy, HydraCacheEntity, SQLx helper, and explicit
get_or_load(...) APIs remain available.
Validation
Release validation passed:
cargo fmt --all -- --checkcargo check --workspace --all-targets --lockedcargo test --workspace --all-targets --lockedcargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo test --doc --workspace --lockedcargo doc --workspace --no-deps --lockedcargo llvm-cov --workspace --all-targets --locked --summary-onlycargo package --workspace --allow-dirty --locked
Coverage summary:
- functions:
100.00% - visible source lines:
100.00% - regions:
98.53%