Reading — step 1 of 5
Read
~1 min readRecursive Resolution
TTL-Based Caching
Every DNS record carries a TTL in seconds. A resolver MUST NOT serve cached records past their TTL.
Cache structure (resolver):
python
Real-world resolvers also do:
- Negative caching (RFC 2308): cache NXDOMAIN responses for the SOA's
minimumfield. - TTL flooring/ceiling: cap TTL at a maximum (e.g., 1 hour) to allow faster refresh, or floor at a minimum.
- Stale-while-revalidate: serve stale data immediately, refresh in background. Improves apparent latency.
- Pre-fetching: when a popular record's TTL is about to expire, refresh proactively.
Cache invalidation: there isn't any in DNS. If you change a record, you must wait for TTLs to expire across all caches. That's why DNS migrations involve "lower TTLs ahead of the change, swap, restore TTLs".
For this lesson: implement TTL-based caching with simulated time.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…