v0.13.0
HydraCache 0.13.0 Release Notes
HydraCache 0.13.0 adds the first ergonomic macro on top of the
database-neutral QueryCachePolicy API.
Highlights
- Added
query_cache_policy!(...). - Re-exported
query_cache_policy!fromhydracache-db. - Re-exported
query_cache_policy!fromhydracache-sqlx. - Added compile-pass and compile-fail tests for policy macro usage.
- Kept loaders explicit through
load(...),fetch_with(...), and SQLx
helper methods.
Example
use hydracache_db::query_cache_policy;
let user_id = 42_i64;
let policy = query_cache_policy!(
name = "load-user",
entity = User,
id = user_id,
tag = "tenant:7",
ttl_secs = 60,
);
let user = queries
.cached_with::<User>(policy)
.load(|| repo.find_user(user_id))
.await?;Manual policies remain available:
let policy = QueryCachePolicy::named("load-user")
.for_cache_entity::<User>(user_id)
.tag("tenant:7")
.ttl(Duration::from_secs(60));Macro Options
entity = Type, id = expr: useCacheEntitymetadata for key and tags.key = expr: set an explicit logical key.collection = expr: set a collection key and tag.name = expr: set a diagnostic operation name.tag = expr: add an invalidation tag; may be repeated.collection_tag = expr: add an escaped collection tag; may be repeated.ttl = expr: set an explicitDuration.ttl_secs = expr: set TTL viaDuration::from_secs(expr).
Exactly one key source is required: entity + id, key, or collection.
Compatibility
This release is additive. Existing QueryCachePolicy, DbQuery, and SQLx
helper APIs continue to work.