pub struct DocumentCache { /* private fields */ }Expand description
Single-flight, TTL-and-negative-cached store for fetched CIMD documents,
keyed by the requested URL. Mirrors
crate::upstream::cache::OauthClientCache’s build_locks pattern:
concurrent callers for the same never-cached (or just-expired) URL
serialize on a per-key lock so only one of them actually performs the
DNS resolution + fetch; the rest wait for and reuse that result.
Unlike OauthClientCache (keyed by (upstream_name, subject), a
cardinality bounded by operator config and authenticated sessions),
build_locks here is keyed by an anonymous, attacker-controlled url
string — so it uses the same MAX_CACHE_ENTRIES threshold entries
does, sweeping out locks nobody currently holds (Arc::strong_count == 1 means only this map references it) whenever a new key is requested
at capacity. This is a softer guarantee than entries’ hard cap: if
every held lock is genuinely busy (an in-flight fetch), a new key still
gets inserted, so sustained full-concurrency load across
MAX_CACHE_ENTRIES+ distinct URLs can transiently exceed the
threshold — self-correcting as those fetches complete and free their
locks, unlike the original unbounded-forever growth this replaced.