Skip to content

v0.14.0

Choose a tag to compare

@javaquasar javaquasar released this 08 Jun 22:34
· 199 commits to main since this release

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!(...) in hydracache-macros.
  • Re-exported cacheable! from hydracache.
  • Required explicit cache, key, and load options.
  • Supported repeated tag options.
  • Supported one TTL option: ttl = Duration or ttl_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-db or hydracache-sqlx for 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 -- --check
  • cargo check --workspace --all-targets --locked
  • cargo test --workspace --all-targets --locked
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo test --doc --workspace --locked
  • cargo doc --workspace --no-deps --locked
  • cargo llvm-cov --workspace --all-targets --locked --summary-only
  • cargo package --workspace --allow-dirty --locked

Coverage summary:

  • functions: 100.00%
  • visible source lines: 100.00%
  • regions: 98.53%