v0.9.0
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::entityfor entity-shaped query results. - Added
DbCache::collectionfor collection-shaped query results. - Added
DbQuery::for_entityto set an entity key and entity tag on an existing
query descriptor. - Added
DbQuery::collection_tagto 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 withSqlxQueryExt.
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 keyuser:42and taguser:42.collection::<T>("users")creates logical keyusersand tagusers.collection_tag("users")adds a tag without changing the current key.- Generated entity and collection segments use
CacheKeyBuilderescaping, 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 -- --checkcargo check --workspace --all-targets --lockedcargo test --workspace --all-targets --lockedcargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo test --doc --workspace --lockedcargo doc --workspace --no-deps --lockedcargo 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.