Skip to main content

Crate hydracache

Crate hydracache 

Source
Expand description

User-facing HydraCache local runtime.

v0 is intentionally local-only: no SQLx adapter, no distributed coordination, and no cluster membership. The goal is a small async cache with TTL, tags, local single-flight, and pleasant loader ergonomics.

§Quick start

use std::time::Duration;

use hydracache::{CacheOptions, HydraCache};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
struct User {
    id: u64,
    name: String,
}

let cache = HydraCache::local()
    .default_ttl(Duration::from_secs(300))
    .max_capacity(10_000)
    .build();

let user = cache
    .get_or_insert_with("user:42", CacheOptions::new().tag("user:42"), || async {
        User {
            id: 42,
            name: "Ada".to_owned(),
        }
    })
    .await?;

assert_eq!(user.id, 42);
cache.invalidate_tag("user:42").await?;

§Typed local cache

use hydracache::{CacheOptions, HydraCache};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
struct User {
    id: u64,
    name: String,
}

let cache = HydraCache::local().build();
let users = cache.typed::<User>("users");

users
    .put(
        "42",
        User {
            id: 42,
            name: "Ada".to_owned(),
        },
        CacheOptions::new(),
    )
    .await?;

let cached = users.get("42").await?;
assert_eq!(cached.map(|user| user.id), Some(42));

Structs§

CacheKey
A logical cache key.
CacheKeyBuilder
Builder for cache keys made of escaped :-separated segments.
CacheOptions
Per-entry cache behavior.
CacheStats
Snapshot of lightweight cache counters.
HydraCache
Local async cache runtime.
HydraCacheBuilder
Builder for a local HydraCache instance.
Options
Per-entry cache behavior.
PostcardCodec
Default compact binary codec for v0.
Stats
Snapshot of lightweight cache counters.
TagSet
A reusable set of cache invalidation tags.
TypedCache
A typed, namespaced view over a HydraCache.

Enums§

CacheError
Errors returned by HydraCache.

Type Aliases§

CacheResult
HydraCache result type.