Skip to content

v0.11.0

Choose a tag to compare

@javaquasar javaquasar released this 02 Jun 10:23
· 205 commits to main since this release

HydraCache 0.11.0 Release Notes

HydraCache 0.11.0 adds a derive macro for domain entity cache metadata.

Highlights

  • Added the publishable hydracache-macros crate.
  • Added #[derive(HydraCacheEntity)].
  • Re-exported HydraCacheEntity from hydracache-db.
  • Re-exported HydraCacheEntity from hydracache-sqlx.
  • Kept manual CacheEntity implementations fully supported.
  • Added compile-pass and compile-fail macro tests with trybuild.
  • Updated live documentation examples to use the derive path.

Example

use hydracache_sqlx::{CacheEntity, HydraCacheEntity};

#[derive(HydraCacheEntity)]
#[hydracache(entity = "user", collection = "users", id = i64)]
struct User;

assert_eq!(User::cache_key_for(&42), "user:42");
assert_eq!(User::entity_tag_for(&42), "user:42");
assert_eq!(User::collection_tag(), Some("users".to_owned()));

Semantics

  • entity is required and becomes CacheEntity::ENTITY.
  • id is required and becomes CacheEntity::Id.
  • collection is optional and becomes CacheEntity::COLLECTION.
  • Generated keys and tags still use the existing CacheKeyBuilder escaping
    rules through the CacheEntity default methods.
  • The macro does not change DbCache, DbQuery, SQLx execution, loaders,
    single-flight, TTLs, or invalidation semantics.

Backward Compatibility

Manual metadata remains valid:

impl CacheEntity for User {
    type Id = i64;

    const ENTITY: &'static str = "user";
    const COLLECTION: Option<&'static str> = Some("users");
}

The full-control descriptor API also remains available:

queries.cached::<User>().key("user:42").tag("user:42")

Publish Order

hydracache-macros is now a published crate. Publish in dependency order:

  1. hydracache-core
  2. hydracache
  3. hydracache-macros
  4. hydracache-db
  5. hydracache-sqlx

Wait for crates.io index propagation between dependent crates.

Validation

  • 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

The SQLx Postgres integration test uses testcontainers. It runs against a real
database when Docker is available and skips successfully when Docker is not
available.

Stable cargo-llvm-cov does not count the exported proc-macro entrypoint as a
normal covered function, even though trybuild executes the macro through
rustc. The macro parser, expansion logic, crate-path resolution, successful
compile cases, and compile-fail diagnostics are covered by unit tests and
trybuild; the remaining function-summary gap is the thin
proc_macro::TokenStream wrapper.