Skip to main content

Module once_map

Module once_map 

Source
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_with for synchronous initializers (file-stat probes, key derivation).
  • OnceMap::get_or_init_async for async initializers (gRPC channel construction, network handshakes). Concurrent inserts for different keys don’t serialize because the lock is released across the await; 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 → V and computes each entry on first access. See module docs for semantics.