Vault
Vault module: ETS-like in-memory key-value store.
Vault tables are mutable, process-global hash tables. They are created once (typically at app startup) and shared across all actors without message passing — every actor that holds the same VaultTable handle sees the same data.
Keys can be any plain value: Int, String, Bool, Atom, Tuple, or Ctor. Function values, Pids, and Tasks cannot be used as keys.
Values are arbitrary March values.
Basic operations: Vault.new(name) — create a named table Vault.set(table, key, value) — insert or overwrite Vault.set_ttl(table, key, value, s) — insert with TTL in seconds Vault.get(table, key) — returns Some(value) or None Vault.drop(table, key) — remove a key (no-op if absent) Vault.update(table, key, fn) — apply fn to existing value Vault.size(table) — number of live entries
TTL semantics: expiry is checked lazily on get/update/size. There is no background sweeper thread; expired entries are evicted on access.
Functions
Create a new named vault table. Returns an opaque table handle.
Insert or overwrite a key-value pair. Removes any previous TTL.
Insert or overwrite a key-value pair with a TTL (time-to-live). The entry expires automatically after ttl_secs seconds. Expiry is checked lazily — no background thread required.
Look up a key. Returns Some(value) if present and not expired, None otherwise.
Remove a key from the table. No-op if the key does not exist.
Apply f to the current value stored at key and replace it with the result. No-op if the key is absent or expired.
Return the number of live (non-expired) entries in the table.
Return the value at key, or default if absent or expired.
Look up a vault table by its registered name. Returns Some(table) if a table with that name exists, None otherwise. Any actor can call this — no handle required.
Return true if key exists in the table and has not expired.
Return all live (non-expired) keys in the table as a List(String).
let t = Vault.new("ex") Vault.set(t, "a", 1) Vault.set(t, "b", 2) List.length(Vault.keys(t)) -- 2
Cost: O(n) where n is the number of entries in the table.
Return all key-value pairs in the table as a list of (String, a) tuples.
Insert or overwrite a key-value pair using a string namespace name. Auto-creates the named vault if it does not yet exist. Useful when you store a namespace string rather than a vault handle.
Vault.ns_set("my_ns", "key", 42)
Look up a key using a string namespace name. Returns None if the namespace does not exist or the key is absent.
Vault.ns_get("my_ns", "key") -- Some(42) or None
Remove a key from a named vault namespace. No-op if the namespace or key is absent.