📝 DNS caching and TTL (10 MCQs)
Temporary Storage of DNS Resource Records
DNS caching stores previously obtained resource records so later queries can be answered without repeating the full hierarchy lookup. Recursive resolvers, operating systems and applications may cache data for a limited period. Caching reduces query traffic and response delay, but stale information can remain available until its permitted lifetime expires. Its distributed structure avoids reliance on one central database for every Internet name worldwide.
How TTL Controls Cache Lifetime
Each cached resource record has a Time to Live (TTL) value expressed in seconds. A cache starts with the received TTL and reduces the remaining lifetime as time passes. When the value reaches zero, the record is no longer valid for ordinary cache reuse and the resolver must obtain fresh information.
Cache Lookup, Expiration and Refresh
When a query arrives, the resolver checks its cache for a matching name, type and class. A valid cached record is returned immediately with its remaining TTL. If the entry has expired or no match exists, the resolver performs the required queries, stores the received record with its TTL and returns the answer.
A Resolver Reusing a Cached A Record
A resolver receives an A record for host.example with TTL 3600 seconds. After 900 seconds, the cached record has approximately 2700 seconds remaining. A later client query can use that cached address without contacting the authoritative server, provided no other cache rules or changes invalidate the entry. The example links a human-readable name to data needed by an application.
Reducing Query Load and Lookup Delay
Caching improves DNS scalability by reducing repeated queries to authoritative infrastructure. It also means a changed address may not be visible everywhere immediately; different caches can retain older records until their TTLs expire. Zone administrators select TTL values to balance cache efficiency against the desired speed of propagation for changes.
Misconceptions About DNS Cache Expiration
'TTL is the time a domain remains registered' confuses cache lifetime with domain registration. 'Every resolver has the same remaining TTL' is false because caches may have received the record at different times. 'Changing an authoritative record instantly clears all caches' is incorrect because ordinary caches generally retain valid old data until expiration.
Calculating and Interpreting DNS TTL Values
For calculations, subtract elapsed time from the original TTL and do not treat it as an absolute clock time. Explain how caching reduces repeated lookups and why a record change may take time to appear. Distinguish positive-record caching from domain registration periods and identify cache expiration as the trigger for re-querying.
DNS Cache and Lifetime Terms
- TTL - Sets a DNS record's cache lifetime.
- DNS cache - Stores previously received DNS data.
- Cache hit - Uses a valid stored answer.
- Cache miss - Requires retrieval of an uncached answer.
- Expiration - Ends ordinary reuse of a cached record.
- Authoritative record - Source data held in a zone.
📝 All DNS caching and TTL MCQs
Q1. If a CPU accesses an address that is not present in the L1 cache, which of the following is the most immediate consequence?
📖 Explanation: When a requested address is absent from L1, the processor cannot supply the data and must retrieve the missing cache line from the next level, typically L2. This fetch introduces a stall while the line is transferred, after which the line is placed in L1 and the instruction can resume. No write‑back or TLB update occurs at this point.
Q2. Given a system with a write-back cache, which inference can be drawn when a dirty cache line is evicted?
📖 Explanation: In a write‑back cache, modified (dirty) lines are kept in the cache until they are evicted. Upon eviction, the dirty line must be written back to main memory to preserve the latest data state. The write‑back occurs before the line is discarded, ensuring memory coherence. No additional copy to L2 is required if the line already resides there.
Q3. Suppose a processor's cache line size is increased from 32 bytes to 128 bytes while keeping the total cache size constant. Deduce the effect on the cache's miss rate for a workload with high spatial locality.
📖 Explanation: Expanding the cache line from bytes to bytes while keeping total cache capacity fixed reduces the number of lines, but each line now contains more contiguous bytes. For workloads exhibiting high spatial locality, successive accesses often fall within the same enlarged line, turning many potential misses into hits. Consequently, the overall miss rate tends to drop significantly.
Q4. Which statement best contrasts direct-mapped and 4-way set-associative caches?
📖 Explanation: In a direct‑mapped cache each memory block maps to exactly one line, so different blocks that map to the same line compete, causing conflict misses. A 4‑way set‑associative cache allows four blocks to occupy the same set, providing flexibility in placement and dramatically lowering conflict misses, which improves the hit rate compared with a direct‑mapped design.
Q5. Evaluating write-through vs. write-back policies, which scenario favors write-back?
📖 Explanation: Write‑back caches defer writing modified data to main memory until eviction, reducing the number of write traffic operations. This is advantageous for workloads that perform many writes because each write updates only the cache line, avoiding repeated memory writes. Read‑heavy or coherence‑critical scenarios usually prefer write‑through to keep memory consistent.
Q6. Differentiate the impact of LRU and FIFO replacement policies on temporal locality. Which statement is true?
📖 Explanation: Temporal locality means recently accessed data is likely to be reused soon. LRU replaces the least recently used line, directly preserving recently accessed items, thus better exploiting temporal locality. FIFO discards the oldest line regardless of recent accesses, which can evict still‑useful data, leading to higher miss rates when temporal locality is strong.
Q7. Apply the LRU principle: In a 3‑way set-associative cache, after accessing blocks X, Y, Z, and then X again, which block becomes the candidate for replacement on the next miss?
📖 Explanation: In a 3‑way set‑associative cache, the three blocks X, Y, and Z occupy the set. Accessing X again updates its recency, making Y the least recently used block. When the next miss occurs, the replacement policy will select Y for eviction because it has not been referenced since the earlier accesses, preserving X and Z.
Q8. Synthesize a caching strategy for a web server that serves both static images and dynamic API responses. Which combination best balances latency and freshness?
📖 Explanation: Static images change rarely, so assigning them a long time‑to‑live (TTL) maximizes cache hits and reduces server load. Dynamic API responses often contain fresh data; a short TTL ensures clients receive up‑to‑date information while still benefiting from brief caching for repeated calls. This mixed approach balances low latency for static content with data freshness for dynamic content.
Q9. Explain the relationship between a multi‑level cache hierarchy and effective memory bandwidth. Which statement is accurate?
📖 Explanation: Effective memory bandwidth perceived by the CPU is the rate at which data can be supplied for execution. Higher‑level caches (L2, L3) act as buffers that capture a large fraction of accesses, shortening the average memory access time and effectively increasing bandwidth. Adding well‑designed cache levels reduces miss penalties, which improves overall throughput.
Q10. What term describes the smallest unit of data that can be transferred between main memory and cache?
📖 Explanation: A cache line, also called a cache block, is the smallest contiguous chunk of memory that can be transferred between main memory and the cache in a single operation. All caches are organized around lines; when a miss occurs, the entire line containing the requested address is fetched and stored, enabling spatial locality exploitation.