Expand description
Response cache with TTL, LRU eviction, and in-flight deduplication.
§Overview
ResponseCache stores the full ServerStatus result for each
(protocol, address) cache key with a configurable TTL. On a cache hit
the stored status is returned instantly with latency = 0.0 and
cached = true.
The cache is disabled by default (TTL = Duration::ZERO). Enable it
via McClientBuilder::response_cache.
§In-flight deduplication (thundering herd protection)
When many tasks concurrently miss the cache for the same key, only one
real ping is performed. The rest subscribe via a tokio::sync::broadcast
channel and receive the result as soon as it arrives.
task-1 ──► cache miss ──► starts real ping ──────────────► insert + broadcast
task-2 ──► cache miss ──► sees in-flight ──► subscribe ──────────────────────► receive
task-3 ──► cache miss ──► sees in-flight ──► subscribe ──────────────────────► receiveThe caller must call insert or
insert_error after the ping completes —
this broadcasts the result to all subscribers and removes the in-flight
entry. If the sender is dropped without broadcasting, subscribers receive
Err(RecvError::Closed) and fall through to a direct ping.
Structs§
- Response
Cache - Response cache: LRU + TTL + in-flight deduplication.