Skip to main content
sitewarm
Purging & invalidation

What are surrogate keys or cache tags?

Surrogate keys, or cache tags, are labels a response carries so you can purge every cached object with that label at once instead of by URL.

Surrogate keys, also called cache tags, are labels the origin attaches to a response in a header, so the CDN indexes the cached object under each label. Purging a label then removes every object that carries it, whatever its URL. Fastly reads them from a space-separated Surrogate-Key header, Cloudflare from a Cache-Tag header.

Surrogate-Key: product-42 category-shoes home
Cache-Tag: product-42,category-shoes,home

Tags let a purge follow your data instead of your URLs. Changing product 42 purges its page, the category pages that list it and the home page, and nothing else.

  • Narrow purges keep the rest of the cache warm, so the hit ratio dips less after a change.
  • The pages you purge are still cold afterwards. Tag purges limit how much needs warming, but they do not warm anything.
  • Header names, separators and limits are vendor-specific, so check your CDN's documentation.

Tag headers differ by CDN: Surrogate-Key on Fastly, Edge-Cache-Tag on Akamai and CDN-Tag on Bunny.net. The Top 10 CDNs comparison covers the rest.

References

  1. Fastly: Surrogate-Keyhttps://www.fastly.com/documentation/reference/http/http-headers/Surrogate-Key/
  2. Cloudflare: Purge cache by cache-tagshttps://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-tags/
  3. Fastly: Getting started with purginghttps://www.fastly.com/documentation/guides/full-site-delivery/purging/getting-started-with-purging/

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.