A cache tag is a label that an origin server attaches to a cached response so that a CDN or reverse proxy can later invalidate every object carrying that label with a single purge request. In content delivery across the Internet, cache tags replace URL-by-URL purging with dependency-based invalidation: content is removed because the data behind it changed, not because someone knows each affected address.
Vendors use different names for the same idea, including surrogate keys, cache-tags and purge tags. The concept is the same in each case: a many-to-many mapping between cached objects and the logical entities, such as a product, an author or a template, that they depend on.
How cache tags link content to cached objects
Cache tags work by sending labels in a response header that the edge stores alongside the cached object. The origin adds a header such as Surrogate-Key or Cache-Tag with a space- or comma-separated list of tags. The edge records each tag in an index that points to all cached objects that carry it, usually in every point of presence.
When the underlying data changes, the application sends one purge call per tag to the CDN API. The CDN looks up the tag index and removes or marks stale every matching object, regardless of its URL, query string or cache key variant. The edge normally strips the tag header before delivering the response to browsers, so the labels stay internal.
The table below traces the life cycle of a tagged object.
| Step | Actor | What happens |
|---|---|---|
| 1. Response generation | Origin server | Adds tags such as product-482 and category-shoes |
| 2. Edge storage | Edge cache | Stores the object and indexes it under each tag |
| 3. Delivery | Edge cache | Serves hits and removes the tag header |
| 4. Data change | Application or CMS | Calls the purge API with product-482 |
| 5. Invalidation | CDN control plane | Purges every object tagged product-482 globally |
Header names and platform limits
There is no single standardized header for cache tags, so each platform defines its own name and limits. The Edge Architecture Specification from the early 2000s introduced the surrogate concept, and several CDNs adopted the Surrogate-Key name from that tradition. Limits on tag length and total header size matter, because an object with hundreds of tags can exceed them and lose some labels silently.
| Platform type | Header name | Typical constraints |
|---|---|---|
| Fastly | Surrogate-Key | Space-separated keys, header size limit of a few kilobytes |
| Cloudflare | Cache-Tag | Comma-separated tags, purge by tag on supported plans |
| Akamai | Edge-Cache-Tag | Comma-separated tags, purge through the Fast Purge API |
| Varnish with xkey | xkey or a custom header | Module-based index in the proxy itself |
| Amazon CloudFront | No native tag purge | Invalidation by path or wildcard only |
Exact limits change between product generations and plans, so the current platform documentation should be checked before a tagging scheme is designed. Where native support is missing, teams often keep their own tag-to-URL index and translate tag purges into path invalidations.
Cache tags compared with other purge methods
Cache tags solve the problem that one data change affects many URLs. A product price appears on the product page, on category listings, on search results and in API responses. URL purging requires the application to know all those addresses, while a tag purge only needs the identifier of the changed entity.
| Method | Precision | Application effort | Best fit |
|---|---|---|---|
| Single URL purge | Exact for one object | High when many pages depend on data | Static assets, isolated pages |
| Wildcard or prefix purge | Coarse | Low | Whole sections or deployments |
| Purge all | None | Minimal | Emergencies, major releases |
| Cache tag purge | Exact by dependency | Moderate, tagging logic at render time | Dynamic sites with shared data |
| Short TTL only | Time based | None | Content that tolerates delay |
Tags also work well with stale-while-revalidate and soft purging. A soft purge marks tagged objects as stale instead of deleting them, so the edge can still serve the old copy while it fetches a fresh one, which protects the origin from a sudden traffic spike after a large invalidation.
Designing an effective tagging scheme
A good tagging scheme mirrors the data model of the application, not its URL structure. Each rendered response receives tags for every entity it displays, plus broader tags for templates or sections. Frameworks and content management systems often generate these tags automatically while rendering, which keeps them consistent with real dependencies.
- Tag by stable identifiers such as product-482 or author-17, not by titles that can change.
- Add a coarse tag per template or section so a layout change can be purged without a full purge.
- Keep tag names short and predictable, and prefix them by environment when staging and production share one CDN account.
- Combine tags with long TTLs, because event-driven invalidation makes long caching safe.
- Monitor purge latency and purge volume, since a single popular tag can invalidate a large share of the cache at once.
The following table helps decide how broadly to tag.
| Content situation | Recommended tags | Reason |
|---|---|---|
| Product detail page | Product, brand and category tags | Price or stock changes must appear quickly |
| Listing or search page | Category tag and a listing tag | Too many entity tags would exceed header limits |
| Shared navigation fragment | Menu or layout tag | One edit affects every page |
| API response | Entity tags matching the payload | Keeps clients and pages consistent |
Common mistakes and failure modes
Most cache tag problems come from missing or excessive tags. A page that omits a dependency keeps showing outdated data after a purge, which is often blamed wrongly on the CDN. A page with too many tags may exceed the header limit and lose the most important ones, or it may be purged so often that the cache hit ratio collapses.
- Forgetting fragment dependencies such as prices in a related-products widget.
- Purging broad tags on every save, which turns frequent editorial work into near-total cache flushes.
- Assuming purge is instant: global propagation typically takes from under a second to several seconds, depending on the platform.
- Leaking internal tags to browsers when the edge is not configured to remove the header.
Explained without jargon
Imagine a library that keeps photocopies of popular pages near the entrance so visitors do not wait. A cache tag is like a colored sticker on each photocopy that says which book it came from.
When a book is corrected, the librarian does not need to remember every copy made from it. She simply removes every copy with that sticker, and fresh copies are made on the next request. That is why cache tags keep fast copies accurate without guesswork.
A typical use case
An online shoe retailer serves about 95 percent of page views from its CDN with a 24-hour TTL. Each product page carries tags for its product, brand and category, and each listing page carries its category tag. When the warehouse system lowers the price of one running shoe, the shop backend sends a single purge request for product-482.
Within a few seconds, the product page, three category listings, the brand page and the JSON response used by the mobile app are refreshed at every edge location. The retailer keeps its high cache hit ratio and correct prices at the same time, instead of choosing between short TTLs and outdated listings.