Course contentsShow
← Cloud and Infrastructure
Lesson 600 of 2,98911. CDN and Edge ComputingFree lesson

Cache Invalidation and Purging

Learn techniques to invalidate cached content across CDN edge locations when updates are deployed.

Cache Invalidation and Purging

What You'll Learn: How to force CDN edge servers to discard outdated cached content when you've updated your origin files.

When you deploy new versions of your website or API, the CDN doesn't automatically know the content has changed. Edge servers might keep serving old cached versions until the TTL expires. Cache invalidation (also called purging or clearing) tells the CDN to immediately remove specific cached objects so the next request fetches fresh content from the origin.

Why Invalidation Matters

Imagine you've just fixed a critical bug in your app.js file, but your CDN cached it with a 24-hour TTL. Without invalidation, users might see the broken version for another day. Invalidation lets you say "forget that cached file right now" so the CDN retrieves your updated version immediately.

How Purging Works

You typically submit an invalidation request through your CDN provider's API, CLI, or console, specifying:

  • Path patterns: /images/logo.png or /css/* (wildcards)
  • Full URLs: Complete paths to specific objects
  • Cache tags: If you've labeled content groups with custom headers

The CDN then propagates this command to all edge locations, marking those objects as stale. The next user request triggers a cache miss, forcing the edge to fetch fresh content from your origin server.

Strategic Considerations

Invalidation isn't instant—it can take seconds to minutes to propagate globally. Some CDN providers charge per invalidation request or limit how many you can submit per hour. Use it strategically: invalidate only changed files rather than clearing your entire cache, which would create a sudden traffic spike to your origin.

Key Takeaway: Cache invalidation forces CDN edge servers to discard specific cached content immediately, ensuring users receive updated files without waiting for TTL expiration—essential for deploying critical updates quickly.