DNS Cache Layer
Trigger: Use when implementing DNS response caching, prefetching, or negative caching.
Key Libraries
- Rust:
lru,moka(high-perf concurrent cache),dashmap,scc - Python:
cachetools,aiocache
Implementation
- Two-tier cache: L1 (hot, moka concurrent, ~10K) + L2 (warm, scc sharded, ~1M)
- TTL-aware eviction with min/max bounds (clamp to configurable range)
- Negative caching: cache NXDOMAIN with short TTL (60-300s) to reduce upstream load
- Prefetch: predict popular domains via frequency tracking; refresh before TTL expiry
- Serialization for persistence via
bincodeormessagepack
Connected Skills
dns-adblock-engine, encrypted-dns-resolver, realtime-dashboard, traffic-analyzer
Pitfalls
- Concurrent eviction + prefetch causes thundering herd — use
moka::try_get_with - Serialization must include expiry timestamps, not just TTL