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(HITorMISS; a pass is reported asMISS), withX-Cache-HitsandX-Served-Bynaming the cache node. With shielding, each value lists one entry per Fastly hop.- TTL controls
Surrogate-Controlsets the Fastly TTL and takes priority overCache-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-Keyheader, 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-revalidateandstale-if-errorsupport.
Watch-outs
X-CacheshowsHITorMISSonly; 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, HITFor 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.
Related terms
Fastly documentation
- Fastly: X-Cachehttps://www.fastly.com/documentation/reference/http/http-headers/X-Cache/
- Fastly: X-Cache-Hitshttps://www.fastly.com/documentation/reference/http/http-headers/X-Cache-Hits/
- Fastly: X-Served-Byhttps://www.fastly.com/documentation/reference/http/http-headers/X-Served-By/
- Fastly: Surrogate-Controlhttps://www.fastly.com/documentation/reference/http/http-headers/Surrogate-Control/
- Fastly: Surrogate-Keyhttps://www.fastly.com/documentation/reference/http/http-headers/Surrogate-Key/
- Fastly: Getting started with purginghttps://www.fastly.com/documentation/guides/full-site-delivery/purging/getting-started-with-purging/
- Fastly: Shieldinghttps://www.fastly.com/documentation/guides/concepts/shielding/
- Fastly: Request collapsinghttps://www.fastly.com/documentation/guides/concepts/cache/request-collapsing/
- Fastly: Staleness and revalidationhttps://www.fastly.com/documentation/guides/concepts/cache/stale/
- 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.