Cache Invalidation Strategies
What you'll learn: How to remove stale content from CDN caches using purge, invalidate, and versioned URL approaches—and when each strategy fits best.
Why Invalidation Matters
You've mastered cache-control headers and conditional requests with ETags. But what happens when you push new content that's already cached at the edge? You need an active way to tell the CDN "forget what you know about this file." That's cache invalidation.
The Three Core Strategies
1. Purge (Hard Delete)
Purge immediately deletes cached objects from all edge locations. It's like erasing a whiteboard completely. The next request fetches fresh content from origin.
Best for: Emergency fixes, security patches, or rarely-changing content that suddenly updated.
2. Invalidate (Soft Refresh)
Invalidation marks cached objects as stale. The CDN may serve the old version briefly while revalidating asynchronously. Think of it as flagging an item for replacement rather than throwing it out immediately.
Best for: High-traffic sites where you want graceful transitions without origin overload.
3. Versioned URLs (Cache Busting)
Instead of invalidating, append unique identifiers to filenames: style.v123.css or app.js?hash=abc456. Each deploy creates new URLs, and old cached versions simply age out naturally.
Best for: Immutable assets like JavaScript bundles, images, or CSS—avoids invalidation costs and complexity entirely.
Comparing Approaches
- Purge: Fast, reliable, but can cause origin stampedes if many users request simultaneously
- Invalidate: Gentler on origin, but stale content may linger briefly
- Versioned URLs: No invalidation needed, infinite caching possible, but requires build-time tooling and HTML updates
Most production systems use versioned URLs for static assets (the "set it and forget it" approach) and purge/invalidate for dynamic pages or APIs.
Key Takeaway: Purge deletes immediately, invalidate marks stale for refresh, and versioned URLs sidestep invalidation entirely—choose based on traffic patterns, urgency, and asset type.