# Dns Cache Layer

> Use when caching DNS responses with TTL and prefetch.

- Skill: `loopyluci/dns-cache-layer` (Agent Skill)
- Install (CLI): `npx skillmds@latest add loopyluci/dns-cache-layer`
- Raw SKILL.md: https://api.skillmd.com/api/skills/loopyluci/dns-cache-layer/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: LoopyLuci (https://skillmd.com/u/loopyluci)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/loopyluci/dns-cache-layer

---


# 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
1. Two-tier cache: L1 (hot, moka concurrent, ~10K) + L2 (warm, scc sharded, ~1M)
2. TTL-aware eviction with min/max bounds (clamp to configurable range)
3. Negative caching: cache NXDOMAIN with short TTL (60-300s) to reduce upstream load
4. Prefetch: predict popular domains via frequency tracking; refresh before TTL expiry
5. Serialization for persistence via `bincode` or `messagepack`

## 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

