Menu

1 / 2

Next.js use cache Explained: Cache Components, cacheLife and cacheTag in Next.js 16.4

DEV Community: nextjs·Waseem Anjum·3 days ago
#uwL5JoHi
#devtonextjs#devto#dev#cache#next
Reading 0:00
15s threshold

Cross-posted from my blog. The original, with any updates, lives on fabwaseem.com .

Next.js use cache is a directive that marks an async function, component or whole file as cacheable, so its output is stored and reused for matching inputs. It is the core of Cache Components , the caching model that Next.js 16.4 now turns on by default in create-next-app . Add 'use cache' , set a lifetime with cacheLife , label it with cacheTag , and invalidate it with updateTag or revalidateTag .

This guide is written against Next.js 16.4.2 and React 19.3 , the current releases. I scaffolded a fresh app with [email protected] (its generated next.config.ts already contains cacheComponents: true and partialPrefetching: true ), wrote every example below, then type-checked, linted, built and ran it with next start . The build output, headers and timestamps shown are the real ones I got back.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.