Skip to main content
InterviewHubPRO
Section Overview
Q17

Question 17 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

34%
Next.js & App Router (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

How do `revalidatePath` and `revalidateTag` work for on-demand cache revalidation?

senior LevelMost AskedCode ExampleFormsSystem Design

In Simple Words: Instead of waiting for a timer to expire, you purge cached data immediately after a user mutation:

  1. revalidatePath(path): Purges the Data Cache and Full Route Cache for a specific URL:
    typescript
    revalidatePath('/products'); // Purges /products route
    
  2. revalidateTag(tag) (More Granular & Scalable): Attach a semantic tag when fetching data:
    typescript
    fetch('https://api.com/products', { next: { tags: ['products-list'] } });
    
    When an admin updates a product, call revalidateTag('products-list'). Every page across the site displaying products is refreshed instantly!