Skip to main content
sitewarm
Rank 2 of 10 on caching criteria

Fastly CDN caching guide

Fastly · reviewed against the vendor documentation listed below

How Fastly caches: X-Cache and X-Served-By headers, Surrogate-Control, purge by surrogate key with soft purge, shielding and request collapsing.

Part of the Top 10 CDNs in 2026 comparison. New to the topic? Start with why cache warming matters.

Caching at a glance

Cache status on the response
X-Cache (HIT or MISS; a pass is reported as MISS), with X-Cache-Hits and X-Served-By naming the cache node. With shielding, each value lists one entry per Fastly hop.
TTL controls
Surrogate-Control sets the Fastly TTL and takes priority over Cache-Control, and Fastly strips it before the response reaches the browser. VCL or Compute code can override TTLs per request.
Purge
Purge a single URL, every object tagged with a surrogate key (Surrogate-Key header, space-separated keys), or the whole service. Soft purge marks content stale instead of evicting it; purge all is always a hard purge.
Tiering and origin protection
Shielding routes misses through one designated shield POP before the origin.
Edge compute
VCL services and Fastly Compute (WebAssembly).

Strengths for caching

  • Surrogate keys and soft purge together let a deploy mark only the changed pages stale, while stale copies stay available for revalidation.
  • Request collapsing is on by default for cache misses, so concurrent misses for one object send one request to the origin.
  • Documented stale-while-revalidate and stale-if-error support.

Watch-outs

  • X-Cache shows HIT or MISS only; a pass and a miss look the same in the header.
  • Without shielding, every POP fills from the origin independently.

Cache warming on Fastly

Fastly caches per POP. With shielding enabled, a miss at an edge POP is fetched through the shield POP, so warming from one location fills the shield as well and other POPs can fill from it instead of the origin.

Read X-Cache together with X-Served-By: with shielding, both carry one value per hop, so MISS, HIT means the edge missed and the shield hit. That tells you whether the shield is warm even when the edge you measured from is not.

curl -sI https://example.com/ | grep -iE '^(x-cache|x-cache-hits|x-served-by)'
# x-served-by: cache-<shield>, cache-<edge>
# x-cache: MISS, HIT

For deploys, tag pages with surrogate keys and soft purge the keys that changed. Soft-purged objects are marked stale, so with stale-while-revalidate visitors get the stale copy while Fastly fetches the new one, which removes most of the thundering herd after a purge. The Top 10 CDNs comparison scores this against other CDNs.

Frequently asked questions

What is the difference between a soft purge and a purge on Fastly?

A purge evicts the object; a soft purge marks it stale, so Fastly can still serve it under stale-while-revalidate or stale-if-error while it fetches a fresh copy. Purge all is always a hard purge.

Why does X-Cache show two values?

With shielding, the request passes through two Fastly caches. Each one appends its result, and X-Served-By lists the matching cache nodes in the same order.

Fastly documentation

  1. Fastly: X-Cachehttps://www.fastly.com/documentation/reference/http/http-headers/X-Cache/
  2. Fastly: X-Cache-Hitshttps://www.fastly.com/documentation/reference/http/http-headers/X-Cache-Hits/
  3. Fastly: X-Served-Byhttps://www.fastly.com/documentation/reference/http/http-headers/X-Served-By/
  4. Fastly: Surrogate-Controlhttps://www.fastly.com/documentation/reference/http/http-headers/Surrogate-Control/
  5. Fastly: Surrogate-Keyhttps://www.fastly.com/documentation/reference/http/http-headers/Surrogate-Key/
  6. Fastly: Getting started with purginghttps://www.fastly.com/documentation/guides/full-site-delivery/purging/getting-started-with-purging/
  7. Fastly: Shieldinghttps://www.fastly.com/documentation/guides/concepts/shielding/
  8. Fastly: Request collapsinghttps://www.fastly.com/documentation/guides/concepts/cache/request-collapsing/
  9. Fastly: Staleness and revalidationhttps://www.fastly.com/documentation/guides/concepts/cache/stale/
  10. Fastly: Computehttps://www.fastly.com/documentation/guides/compute/

Warm your cache after every deploy

sitewarm requests the pages in your sitemap after a deploy and reports the cache state the CDN returns for each one, with the vantage point it was measured from.