Capy-Bearer Documentation

kv_set

lib call

Capy

function kv_set(key : string, value : as any, ttl_seconds : u64 = 3600) bool

Description

kv_set() stores a copy of value under key in the shared cache. A later kv_set() replaces the entry and its expiry. A value larger than one megabyte is not stored and the call returns false.

The cache has a fixed size (KV_CACHE_BYTES, 64 MB by default). When it is full, the least recently used entries make room. Contents live as long as the runtime process does.

Parameters

key : the entry key, at most 1024 bytes

value : the value to store, any any shape

ttl_seconds : seconds until the entry expires, 0 for no expiry

Return Values

true when the value was stored

Example

Capy

print(kv_set("doc-count", any(3), 60), " ", s64(kv_get("doc-count")), "\n")

Output

true 3