Skip to content

Lesson 4 of 9 · 23m

Cloudflare Cache Architecture

Where objects actually live, how tiered cache works, and why hit ratio is an architecture metric rather than a vanity number.

Caching is the highest-leverage feature of an edge network and the easiest one to misunderstand. "Cloudflare cache" is not one big shared memcached in the sky. Objects are cached in individual PoPs, then optionally backed by tiered cache layers, and your origin remains the authority whenever the edge cannot answer.

The object lifetime is controlled by headers

Cloudflare honors standard HTTP cache semantics first:

Cache-Control: public, max-age=300, s-maxage=3600, stale-while-revalidate=60
ETag: "v18-banner-2026-11"
Vary: Accept-Encoding

s-maxage is the shared-cache lifetime — the one intermediaries such as Cloudflare use. max-age is for browsers. private, no-store, or a Set-Cookie on an otherwise cacheable response are the usual reasons an object silently refuses to cache.

A response can be perfect HTTP and still not cache because Cloudflare's default cache behavior only covers certain file extensions and methods. Everything else needs a Cache Rule.

Cache Rules are explicit policy

A sane static-asset rule looks like:

When incoming requests match:
  http.request.uri.path wildcard "/assets/*"

Then:
  Cache eligibility: Eligible for cache
  Edge TTL: 1 month
  Browser TTL: 1 hour

For HTML, be conservative. For fingerprinted assets such as /assets/app.8f31c2.js, cache aggressively because the URL changes when content changes. Immutable filenames are what make long TTLs safe.

Tiered cache reduces origin thundering herds

Without tiering, every PoP can miss independently and hammer the origin. Tiered Cache routes misses through upper-tier Cloudflare locations so one regional miss can serve many edge PoPs. Smart Tiered Cache topology selects those upper tiers dynamically.

edge PoP miss -> upper tier hit? -> upper tier miss -> origin

This matters most after deploys or invalidations: the origin sees fewer duplicated misses. It does not make invalidation instant, and it does not make inconsistent content impossible.

Read cache status like an operator

CF-Cache-Status tells you what happened: HIT, MISS, EXPIRED, STALE, BYPASS, DYNAMIC, REVALIDATED. Age tells you how long the object has been sitting in cache. cf-cache-status plus cf-ray is often enough to reconstruct the request path during an incident.

Field notes

  • Cookies do not automatically poison every response, but Set-Cookie usually does. Strip cookies only when you are certain the response is not personalized.
  • Vary multiplies cache entries. Vary: User-Agent is how you accidentally create thousands of copies of the same page.
  • Cache hit ratio means little without segmentation. Static assets should be near-perfect; authenticated HTML usually is not.
  • Bypass cache for admin and preview routes deliberately. "It only affects staff" is still an outage when staff cannot fix the site.

Was this lesson helpful?

Sign in to rate