cache invalidation
Marking cached copies as out of date, or deleting them, when the real data changes so the next read fetches fresh data.
In more detail
Invalidate too little and users see stale data; invalidate too much and the source is flooded with refetches. Targeted strategies include hierarchical keys, tags on cached items and messages that tell every copy to drop an entry.
Examples
TanStack Query key prefixes, surrogate tags for server caches, and Redis pub/sub to clear every node’s local copy.After saving a profile, invalidate the related keys and React components refresh, suspending again if needed.Related terms
- cache — A store of earlier answers kept close to where they are needed so they can be reused instead of fetched or computed again.
- query key — The array that names a piece of cached server data in TanStack Query, such as ["users", "detail", "10"].
- surrogate key — An extra label attached to cached items, such as product-42 or shop, so that every item with that label can be purged in one go.
- publish-subscribe — A messaging pattern where senders publish messages to a named channel and every subscriber listening on that channel receives a copy.
- stale data — Data that was correct when it was read or cached but no longer matches the source of truth because it has since changed.
- revalidateTag — A function from next/cache that invalidates every cached entry labelled with a given tag, across all routes.
- revalidatePath — A function from next/cache that invalidates cached data and pages for a given URL path.
- router.refresh() — A method that clears the Router Cache for the current route and asks the server for a fresh render, keeping client state.
- cache key — The name a cache entry is saved and looked up under, usually built from the operating system and a hash of the lock file.
- TTL — How long a stored item, such as a session, token or cache entry, stays valid before it expires.
- expiry — The automatic removal of data once its time to live has passed.
- stale read — A read that returns an older value than the latest committed write.
- versioned key — A cache key that includes the data's version, so a write simply moves readers to a new key.
Taught in
- Unified Build Pipelines: Caching & Dependency Graphs — Production Full-Stack Engineering
- Type-Safe Client Generation: Orval & Automated SDKs — Production Full-Stack Engineering
- Optimistic UI Architecture: Cache & Rollback Protocols — Production Full-Stack Engineering
- Distributed Cache Invalidation: Redis & Tagged Purging — Production Full-Stack Engineering
- Data Cache: Cross-Request Persistence & Fetch Tags — Next.js 15 & Modern App Router Architecture
- Full Route Cache: Static Rendering & Segment Config — Next.js 15 & Modern App Router Architecture
- Router Cache: In-Memory Client Prefetch Semantics — Next.js 15 & Modern App Router Architecture
- Revalidation Strategies: revalidatePath & Cache Life — Next.js 15 & Modern App Router Architecture
- Session Management: Secure Cookies & Token Validation — Next.js 15 & Modern App Router Architecture
- Client-Side Data Fetching Architectures with Suspense — React 19 & Modern Component Architecture
- Eventual Consistency And What It Costs A Product — Scalable System Design & Distributed Architecture
- Caching Strategies And Topology — Scalable System Design & Distributed Architecture
- Cache Invalidation And The Three Hard Cases — Scalable System Design & Distributed Architecture