Skip to content

v0.7.0

Choose a tag to compare

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

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-db workspace crate.
  • hydracache-sqlx workspace crate over hydracache-db.
  • DbCache namespaced adapter over an existing HydraCache.
  • DbQuery<T> query result-cache descriptor.
  • DbCache::cached::<T>() for cache descriptors without duplicate SQL text.
  • DbCache::named::<T>("name") for optional diagnostic labels.
  • SqlxCache and SqlxQuery compatibility aliases from hydracache-sqlx.
  • Explicit query keys via key and key_builder.
  • Query tags via tag, tags, and tag_set.
  • Per-query TTL via ttl.
  • fetch_with for cache lookup plus caller-owned SQLx loading.
  • DbCacheError::MissingKey for 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 -- --check
  • cargo check --workspace --all-targets --locked
  • cargo test --workspace --locked
  • cargo test -p hydracache-sqlx --test postgres_testcontainers --locked -- --nocapture
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --locked
  • cargo 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.