Expand description
Single-flight locking for cache-stampede protection.
FusionCache guarantees that, per key, only one factory runs at a time; other callers await that result. We implement this with a fixed bank of sharded async mutexes: a key always maps to the same shard, so concurrent calls for the same key serialize on the same lock. Distinct keys that happen to share a shard may serialize too, but this only affects throughput, never correctness — after acquiring the lock each caller re-checks its own key.
Sharding (rather than a per-key map) keeps memory bounded and side-steps the
notoriously race-prone “remove the lock entry when the last waiter leaves”
cleanup. The guard is an OwnedMutexGuard so it is 'static + Send and can
be moved into a spawned background task (needed for background factory
completion and eager refresh).
Structs§
- Keyed
Lock - A bank of sharded async mutexes providing per-key single-flight.
Type Aliases§
- KeyGuard
- The guard returned by acquiring a key’s lock. Releasing it (on drop) lets the next waiter for that shard proceed.