Edge Cache Key & Purge Lab (Interactive)
Compose cache keys from Vary headers, watch fragmentation crater the hit ratio, then purge by Surrogate Key. Toggle cache-key components against a real LRU capacity model, then hard- or soft-purge a product tag and measure latency spikes and origin fetch storms.
Edge Cache Key & Purge Lab
Compose the cache key, watch Vary fragmentation destroy the hit ratio, then purge with Surrogate Keys.
Cache key = Hash(components)
Global invalidation (Surrogate-Key: product-102)
One tag purge invalidates product page + category tiles + search fragments in <150ms (Shopify/Fastly pattern).
Healthy CDNs absorb 85–98% of traffic; below 50% the edge has become a pass-through.
Cache-Control recipe
public, max-age=3600,
s-maxage=2592000, stale-while-revalidate=86400
max-age = browser; s-maxage = shared CDN edge.
How It Works Under the Hood
Edge nodes look up requests by a composite key — Hash(scheme, host, path, query, Vary headers) — not the URL alone. Every Vary dimension multiplies stored variants: Accept-Encoding triples them, while Vary: User-Agent with thousands of distinct strings shatters a 95% hit ratio into cache-busting fragments that thrash the PoP's finite NVMe capacity. When a price changes, Surrogate-Key tags let the backend purge every related page across 300 PoPs with one API call; a hard purge makes the next visitors eat full miss latency, whereas a soft purge marks entries stale so stale-while-revalidate keeps serving 5ms responses while the origin refreshes asynchronously.
Core Architectural Principles
- Cache key = Hash(URI + Host + Query + Vary); each varied dimension multiplies distinct stored variants.
- Vary: User-Agent fragments the cache into thousands of buckets — normalize to X-Device at the edge worker.
- Surrogate-Key tag purge invalidates thousands of related URLs in <150ms; soft purge + SWR hides the miss spike.
Talk cache invalidation with precision: tag-based purge via Surrogate-Keys for surgical global eviction, soft purge with stale-while-revalidate to eliminate latency spikes, and header normalization so Vary never explodes cardinality. Quantifying hit-ratio loss from Vary: User-Agent instantly signals production experience.
Rich per-variant personalization gives razor-precise caching, but unnormalized keys and hard purges convert the edge into an expensive origin passthrough.