Course contentsShow
← Web Development
Lesson 1800 of 2,98233. Static Site Generation and JamstackFree lesson

Cache Invalidation Strategies

Understanding how ISR manages cache purging, what triggers invalidation, and ensuring users see fresh content.

Cache Invalidation Strategies

What you'll learn: How Incremental Static Regeneration (ISR) decides when to purge cached pages and deliver fresh content to users.

Understanding Cache Invalidation in ISR

When you use ISR, your statically generated pages are cached and served from a CDN. But how does the system know when that cached copy is outdated and needs replacing? This is where cache invalidation comes in—the process of removing or replacing stale cached content.

Think of it like a grocery store's inventory system. The store keeps products on shelves (cache) but needs rules for when to restock or remove expired items. Similarly, ISR needs strategies to determine when cached pages should be refreshed.

Key Invalidation Triggers

Time-Based Invalidation

The revalidate interval you configured (like revalidate: 60) acts as an automatic trigger. After this time passes, the next visitor triggers a background rebuild while still receiving the cached version.

On-Demand Invalidation

You can manually purge specific pages when content changes—like when an editor publishes a new blog post. This is immediate and doesn't wait for the revalidation timer.

Fallback Creation

When a new dynamic route is accessed that doesn't exist yet, ISR generates and caches it on-the-fly, effectively creating a new cache entry.

Ensuring Fresh Content

The beauty of ISR's stale-while-revalidate pattern is that users rarely wait for builds. They see cached content immediately while the system updates in the background. The next visitor gets the fresh version. For time-sensitive updates, combine short revalidation intervals with on-demand invalidation to give you fine-grained control.

Key Takeaway: ISR cache invalidation happens through time-based revalidation intervals and on-demand purging, ensuring users see fast, reasonably fresh content without manual rebuilds.