Skip to content

v0.8.0

Choose a tag to compare

@javaquasar javaquasar released this 01 Jun 12:59
· 210 commits to main since this release

HydraCache 0.8.0 Release Notes

HydraCache 0.8.0 makes the SQLx adapter more ergonomic while keeping the
database-neutral cache boundary intact.

Highlights

  • Added SqlxQueryExt in hydracache-sqlx.
  • Added fetch_one, fetch_optional, and fetch_all helpers for common
    pool-backed SQLx reads.
  • Kept fetch_with as the escape hatch for SQLx macros, transactions,
    repository methods, and custom database flows.
  • Added DbQuery::fetch_value_with for adapter crates that need to cache
    shapes such as Option<T> and Vec<T>.
  • Extended the real Postgres testcontainers integration test to cover helper
    cache hits, optional results, list results, tag invalidation, and failed SQL
    not being cached.

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
    .cached::<(i64, String)>()
    .key("user:42")
    .tag("user:42")
    .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

  • Cache hits do not execute SQLx.
  • Cache misses execute SQLx once per key under local single-flight.
  • fetch_optional caches None.
  • fetch_all caches empty vectors.
  • SQLx failures are returned and are not stored.

Validation

  • cargo fmt --all
  • cargo check --workspace --all-targets
  • cargo test --workspace --all-targets
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo test --doc --workspace --locked
  • cargo doc --workspace --no-deps --locked
  • cargo package -p hydracache-core --locked --allow-dirty

Dependent package verification must be run in publish order after
hydracache-core 0.8.0 is available on crates.io.