Skip to main content

Module kv

Module kv 

Source
Expand description

Reusable in-memory key-value store

This module provides KvStore, a thread-safe, cloneable, in-memory key-value store with optional per-key TTL, quota enforcement, atomic increment / compare-and-swap, and a broadcast-based watch capability.

It was extracted from the WASM DefaultHost so external consumers (daemons, tests, other runtimes) can use the same store natively. The WASM host now delegates to this type, so behaviour is identical across both paths.

§Sharing

KvStore holds its state behind an Arc, so cloning a KvStore produces a handle to the same underlying store. Writes go through interior mutability (a parking_lot::RwLock), which is why the mutating methods take &self rather than &mut self — a clone can write through to the shared store concurrently.

§Watch

Every successful mutation publishes a KvEvent over a tokio::sync::broadcast channel. Use KvStore::subscribe for the raw receiver or KvStore::watch_prefix for a filtered futures_util::Stream.

Structs§

KvEntry
Key-value entry with optional TTL
KvEvent
A change event published to watchers when the store is mutated.
KvStore
Thread-safe, cloneable, in-memory key-value store.

Enums§

KvError
Key-value storage error types matching WIT kv-error variant
KvEventKind
The kind of mutation that produced a KvEvent.

Traits§

KvBackend
A pluggable asynchronous backend for KvStore.

Functions§

global_kv
Fetch a clone of the daemon’s process-global KvStore, if one has been published via set_global_kv.
set_global_kv
Publish the daemon’s KvStore handle to the process-global slot.