#[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&CacheKitparameter.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’sinterop=/ TypeScript’sinterop:.namespace = "<string>"(required): interop/v1 namespace segment, same grammar.secure(optional flag): Use encrypted cache viacache.secure().
§Requirements
- Every non-client argument must be a plain identifier (no destructuring
patterns, no
self) and must convert intocachekit::interop::InteropValueviaFrom(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::Serializationbefore the body runs: non-finite floats (NAN,±INFINITY) andi128outside[-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}") })
}