What is cache invalidation, or a CDN purge?
Cache invalidation, or purging, removes or marks stale cached copies before their TTL ends, so the CDN fetches the new version from the origin.
Cache invalidation, also called purging, is telling a CDN to stop serving its cached copies of some content before their TTL ends. You purge after a deploy or a content change so visitors see the new version. The next request for each purged object is a miss that goes to the origin, unless a stale copy may be served.
# by URL, by tag, by prefix, or everything
PURGE https://example.com/pricing
purge tag: product-42
purge everythingPurges differ in scope and in strength:
- Scope: one URL, a prefix, a host, a tag or surrogate key, or the whole cache.
- Hard purge: the object is removed. Akamai calls this delete, and the next request must fetch the full object.
- Soft purge: the object is marked stale but kept. Fastly soft purge and Akamai invalidate work this way, so the cache can revalidate it cheaply or serve it under `stale-while-revalidate`.
- Amazon CloudFront invalidations remove files from edge caches, so the next viewer request goes to the origin. Versioned file names avoid the need.
Either way the cache is cold for the purged pages until they are requested again. That is the moment cache warming is for.
Which CDNs can mark content stale instead of deleting it is compared in the Top 10 CDNs comparison; the Fastly and Vercel guides cover soft purge and invalidation by tag.
Related terms
References
- Fastly: Getting started with purginghttps://www.fastly.com/documentation/guides/full-site-delivery/purging/getting-started-with-purging/
- Akamai: Purge cachehttps://techdocs.akamai.com/purge-cache/docs/welcome-purge
- Amazon CloudFront: Invalidate files to remove contenthttps://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html
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.