Expand description
Process-lifetime per-key cache.
OnceMap<K, V> is the shape that the CLI’s daemon detection and mount
lifecycle code all reach for independently: a process-wide HashMap
whose entries are computed on first access and held until the process
exits. The repeated OnceLock<Mutex<HashMap<K, V>>> ceremony at each
call site disappears behind a single type.
Two construction modes:
OnceMap::get_or_init_withfor synchronous initializers (file-stat probes, key derivation).OnceMap::get_or_init_asyncfor async initializers (gRPC channel construction, network handshakes). Concurrent inserts for different keys don’t serialize because the lock is released across theawait; concurrent inserts for the same key may both run the init future (last writer wins) — this matches the behavior of every call site that previously used this pattern.
Values are cloned on read. Use a cheaply-cloneable handle (Arc<…>,
tonic::transport::Channel) when the underlying object is expensive
to clone.
Structs§
- OnceMap
- A process-lifetime cache that maps
K → Vand computes each entry on first access. See module docs for semantics.