v0.7.0
HydraCache 0.7.0
Summary
0.7.0 introduces hydracache-db, the database-neutral result-cache adapter
crate, and hydracache-sqlx, the first SQLx-facing integration crate.
The release starts the SQLx direction carefully: SQLx remains responsible for
database execution, compile-time macros, pools, transactions, and row mapping.
HydraCache owns the cache boundary around that execution: explicit keys, tags,
TTL, local single-flight, serialization, and invalidation.
Added
hydracache-dbworkspace crate.hydracache-sqlxworkspace crate overhydracache-db.DbCachenamespaced adapter over an existingHydraCache.DbQuery<T>query result-cache descriptor.DbCache::cached::<T>()for cache descriptors without duplicate SQL text.DbCache::named::<T>("name")for optional diagnostic labels.SqlxCacheandSqlxQuerycompatibility aliases fromhydracache-sqlx.- Explicit query keys via
keyandkey_builder. - Query tags via
tag,tags, andtag_set. - Per-query TTL via
ttl. fetch_withfor cache lookup plus caller-owned SQLx loading.DbCacheError::MissingKeyfor descriptors without explicit keys.- Post-publish verification coverage for the SQLx adapter crate.
- Postgres testcontainers integration coverage for
hydracache-sqlx.
Example
use hydracache::HydraCache;
use hydracache_db::DbCache;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
struct User {
id: i64,
name: String,
}
# async fn example() -> hydracache_sqlx::Result<()> {
let local = HydraCache::local().build();
let queries = DbCache::new(local, "db");
let user = queries
.cached::<User>()
.key("user:42")
.tag("user:42")
.fetch_with(|| async {
Ok::<_, std::io::Error>(User {
id: 42,
name: "Ada".to_owned(),
})
})
.await?;
# Ok(())
# }Why fetch_with First
The adapter does not hide SQLx behind a second query API yet. That is deliberate:
the first version should be easy to reason about, easy to test, and hard to
misuse.
Applications can keep using sqlx::query!, sqlx::query_as!, transactions,
pools, and their own connection lifetimes. HydraCache only wraps the result with
cache behavior.
cached::<T>() is the preferred entry point because it avoids duplicating SQL
text in the cache descriptor and in the SQLx loader. named::<T>("load-user")
can be used when diagnostics need a human-readable operation name. query_as
is kept as a compatibility/diagnostic alias when the SQL text itself is a useful
label.
Verification
cargo fmt --all -- --checkcargo check --workspace --all-targets --lockedcargo test --workspace --lockedcargo test -p hydracache-sqlx --test postgres_testcontainers --locked -- --nocapturecargo clippy --workspace --all-targets --all-features --locked -- -D warningsRUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --lockedcargo package -p hydracache-core --locked --allow-dirty
The Postgres integration test uses testcontainers. It runs against a real
Postgres container when Docker is available and skips cleanly when Docker is not
available in the environment.
hydracache, hydracache-db, and hydracache-sqlx package verification
requires hydracache-core 0.7.0 and then hydracache 0.7.0 to be visible in
the crates.io index first.
MSRV Dependency Note
hydracache-sqlx adds SQLx and testcontainers integration coverage, which
pulls modern async/database ecosystem dependencies. HydraCache now declares Rust
1.88 as MSRV for 0.7.0, allowing the lockfile to use current ICU/IDNA and
testcontainers dependency graphs instead of pinning older transitive versions.
The earlier Rust 1.85 pinning decision is tracked historically in
TD-0001.