v0.8.0
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
SqlxQueryExtinhydracache-sqlx. - Added
fetch_one,fetch_optional, andfetch_allhelpers for common
pool-backed SQLx reads. - Kept
fetch_withas the escape hatch for SQLx macros, transactions,
repository methods, and custom database flows. - Added
DbQuery::fetch_value_withfor adapter crates that need to cache
shapes such asOption<T>andVec<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_optionalcachesNone.fetch_allcaches empty vectors.- SQLx failures are returned and are not stored.
Validation
cargo fmt --allcargo check --workspace --all-targetscargo test --workspace --all-targetscargo clippy --workspace --all-targets --locked -- -D warningscargo test --doc --workspace --lockedcargo doc --workspace --no-deps --lockedcargo 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.