Caching Strategies Medium technical 1 views 1 min read

How does HTTP caching work with Cache-Control and ETag?

Peer-reviewed by HireXTech Technical Panel • Updated for 2025/2026 hiring • Editorial standards
Practise this track
Interviewer Expectations for this Question
01
Core Competency

Assesses fundamental understanding of Caching Strategies conventions, runtime behavior, and memory/performance considerations.

02
Evaluation Criteria

Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.

Comprehensive Model Answer Verified Solution

HTTP caching lets browsers and proxies reuse responses. Cache-Control sets the policy:

  • max-age=300: fresh for 300 seconds; no revalidation needed.
  • s-maxage: overrides max-age for shared caches such as CDNs.
  • private vs public: whether shared caches may store it. Never mark personalized responses public.
  • no-store: do not cache at all; no-cache: store but always revalidate.
  • stale-while-revalidate and immutable: serve stale while refreshing, or never revalidate a fingerprinted asset.

ETag enables conditional requests: the client sends If-None-Match, and the server replies 304 Not Modified with no body if unchanged, saving bandwidth.

ETag: "abc123"
If-None-Match: "abc123"  ->  304 Not Modified

Use content-hashed filenames with long immutable cache times for static assets, and short, revalidated caching for HTML and dynamic data. Vary correctly when responses depend on headers such as Accept-Encoding.

Candidate Response Strategy & Interview Tips

  1. Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
  2. Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
  3. Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
  4. Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.
Related Topics & Skills
Spotted an error or have an alternative solution?