Skip to main content

cachekit

Attribute Macro cachekit 

Source
#[cachekit]
Expand description

Cache the result of an async function under an interop/v1 cache key.

Keys are {namespace}:{operation}:{args_hash} per the protocol’s interop-mode spec, so the same entry is addressable from the Python and TypeScript SDKs — Python’s @cache(interop="get_user", namespace="users") computes the identical key for the same arguments.

§Attributes

  • client = <ident> (required): Name of the &CacheKit parameter.
  • ttl = <integer> (required): TTL in seconds.
  • interop = "<string>" (required): explicit, language-neutral operation segment (^[a-z0-9][a-z0-9._-]{0,63}$) — same meaning as Python’s interop= / TypeScript’s interop:.
  • namespace = "<string>" (required): interop/v1 namespace segment, same grammar.
  • secure (optional flag): Use encrypted cache via cache.secure().

§Requirements

  • Every non-client argument must be a plain identifier (no destructuring patterns, no self) and must convert into cachekit::interop::InteropValue via From (bool, i32/i64/ u32/u64/i128, f64, &str/String, Uuid). Unsupported argument types fail at compile time.
  • In-model values outside the interop ranges fail at CALL time with CachekitError::Serialization before the body runs: non-finite floats (NAN, ±INFINITY) and i128 outside [-2^63, 2^64-1]. This fail-loud contract matches the Python and TypeScript SDKs — silently running uncached would mask cross-SDK key divergence.
  • The client must be built without .namespace() / CACHEKIT_NAMESPACE — interop keys carry their own namespace segment, and reads fail closed on a namespaced client.
  • A stored entry that cannot be decoded as the return type is treated as a miss and overwritten (self-healing), never an error loop.

§Example

ⓘ
#[cachekit(client = cache, ttl = 60, interop = "get_user", namespace = "users")]
async fn get_user(cache: &CacheKit, id: u64) -> Result<User, CachekitError> {
    Ok(User { name: format!("User {id}") })
}