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
- KvEvent
Kind - The kind of mutation that produced a
KvEvent.
Traits§
Functions§
- global_
kv - Fetch a clone of the daemon’s process-global
KvStore, if one has been published viaset_global_kv. - set_
global_ kv - Publish the daemon’s
KvStorehandle to the process-global slot.