Course contentsShow
← Cloud and Infrastructure
Lesson 596 of 2,98911. CDN and Edge ComputingFree lesson

TTL and Cache Control Headers

Understand Time-to-Live settings and how Cache-Control headers influence CDN caching decisions.

TTL and Cache Control Headers

What you'll learn: How to control how long CDNs cache your content using TTL settings and HTTP headers.


The Core Idea

When a CDN caches your content at the edge, it needs to know how long that cached copy stays fresh before checking back with your origin server. Time-to-Live (TTL) is the duration (in seconds) that tells the CDN: "You can serve this cached copy for X seconds before asking me for a fresh one."

Cache-Control headers are HTTP instructions you send in your response that tell CDNs and browsers exactly how to cache content. These headers override default CDN behaviors and give you fine-grained control.

Common Cache-Control Directives

  • max-age=3600 – Cache this for 3600 seconds (1 hour)
  • no-cache – Must revalidate with origin before serving (doesn't mean "don't cache")
  • no-store – Don't cache this at all (sensitive data)
  • public – Any cache can store this (CDN, browser)
  • private – Only user's browser can cache (not CDN)

Real-World Analogy

Think of a newspaper stand (CDN edge). The distributor (origin) tells the stand owner: "Sell today's paper until midnight (TTL), then grab tomorrow's edition." The Cache-Control header is like the distributor's instructions printed on each delivery bundle.

How CDNs Decide What to Cache

  1. Check the Cache-Control header from your origin response
  2. If no header exists, use the CDN's default TTL (often configurable)
  3. Respect no-store and private directives absolutely
  4. Honor max-age for determining cache freshness

Key Takeaway:
TTL and Cache-Control headers are your primary tools for controlling CDN caching behavior—use max-age to set cache duration and directives like public or private to define where content can be cached.