Skip to content

v0.9.0

Choose a tag to compare

@javaquasar javaquasar released this 01 Jun 14:17
· 207 commits to main since this release

HydraCache 0.9.0 Release Notes

HydraCache 0.9.0 adds database query ergonomics on top of the explicit
hydracache-db and hydracache-sqlx APIs.

Highlights

  • Added DbCache::entity for entity-shaped query results.
  • Added DbCache::collection for collection-shaped query results.
  • Added DbQuery::for_entity to set an entity key and entity tag on an existing
    query descriptor.
  • Added DbQuery::collection_tag to associate entity results with broader
    invalidation groups.
  • Kept cached().key().tag().ttl().fetch_with(...) as the full-control API.
  • Extended the real Postgres testcontainers integration test to verify the new
    helpers with SqlxQueryExt.

Example

use hydracache::HydraCache;
use hydracache_sqlx::{DbCache, SqlxQueryExt};

# async fn example(pool: sqlx::PgPool) -> hydracache_sqlx::Result<()> {
let cache = HydraCache::local().build();
let queries = DbCache::new(cache, "db");

let (id, name): (i64, String) = queries
    .entity::<(i64, String)>("user", 42)
    .collection_tag("users")
    .fetch_one(
        pool.clone(),
        sqlx::query_as("select id, name from users where id = $1").bind(42_i64),
    )
    .await?;

assert_eq!(id, 42);
assert!(!name.is_empty());
# Ok(())
# }

Semantics

  • entity::<T>("user", 42) creates logical key user:42 and tag user:42.
  • collection::<T>("users") creates logical key users and tag users.
  • collection_tag("users") adds a tag without changing the current key.
  • Generated entity and collection segments use CacheKeyBuilder escaping, so
    : and % inside one segment cannot accidentally create extra segments.
  • Explicit .key(...) can still override a generated key when needed.

Backward Compatibility

The existing .cached::<T>().key(...).tag(...).ttl(...).fetch_with(...) API is
unchanged and remains the full-control layer. The new helpers are ergonomic
shortcuts over the same descriptor model, not a replacement.

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 package -p hydracache-core --locked --allow-dirty

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.

Dependent package verification must be run in publish order after
hydracache-core 0.9.0 and then hydracache 0.9.0 are available on crates.io.