v0.10.0
HydraCache 0.10.0 Release Notes
HydraCache 0.10.0 adds domain entity cache metadata for database result
caching.
Highlights
- Added
CacheEntityinhydracache-db. - Re-exported
CacheEntityfromhydracache-sqlx. - Added
DbCache::for_entity<T: CacheEntity>(id). - Added
DbQuery::for_cache_entity(id)for existing descriptor chains. - Automatically adds the entity tag and optional collection tag from metadata.
- Kept
entity(kind, id),collection(name), and the explicit
.cached().key().tag()API unchanged. - Extended unit tests and real Postgres SQLx integration tests for the new
metadata-driven path.
Example
use hydracache::HydraCache;
use hydracache_sqlx::{CacheEntity, DbCache};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
struct User {
id: i64,
name: String,
}
impl CacheEntity for User {
type Id = i64;
const ENTITY: &'static str = "user";
const COLLECTION: Option<&'static str> = Some("users");
}
# async fn example() -> hydracache_sqlx::Result<()> {
let queries = DbCache::new(HydraCache::local().build(), "db");
let user = queries
.for_entity::<User>(42)
.fetch_with(|| async {
Ok::<_, std::io::Error>(User {
id: 42,
name: "Ada".to_owned(),
})
})
.await?;
assert_eq!(user.id, 42);
# Ok(())
# }Semantics
CacheEntity::ENTITYprovides the entity key/tag prefix.CacheEntity::COLLECTIONoptionally provides a broader invalidation tag.DbCache::for_entity::<User>(42)creates keyuser:42, taguser:42, and
tagusersfor the example above.DbQuery::for_cache_entity(42)applies the same metadata to an existing
descriptor and preserves existing tags.- All generated segments use
CacheKeyBuilderescaping.
Backward Compatibility
The 0.9.0 helpers remain available:
queries.entity::<User>("user", 42).collection_tag("users")The full-control API also remains available:
queries.cached::<User>().key("user:42").tag("user:42")CacheEntity is an additive metadata layer and the intended future expansion
target for a derive macro.
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 llvm-cov --workspace --all-targets --locked --summary-onlycargo 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.10.0 and then hydracache 0.10.0 are available on
crates.io.