> nextjs-caching
Configure the 4 caching layers in Next.js: request memoization, data cache, full-route cache, and router cache. Use when setting revalidation strategies, invalidating cached data with tags, or diagnosing stale data bugs. (triggers: **/page.tsx, **/layout.tsx, **/action.ts, unstable_cache, revalidateTag, Router Cache, Data Cache)
curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/nextjs-caching?format=md"Caching Architecture
Priority: P1 (HIGH)
Next.js has 4 distinct caching layers. Understanding them prevents stale data bugs.
Workflow: Configure Caching for a Feature
- Choose cache strategy — SSG (
force-cache), ISR (revalidate: N), or SSR (no-store). - Tag cacheable fetches — Add
next: { tags: ['posts'] }to fetch options. - Invalidate on mutation — Call
revalidateTag('posts')in Server Actions. - Deduplicate requests — Wrap shared data fetches with React
cache(). - Clear client cache — Use
router.refresh()after client-side mutations.
Cache Invalidation Example
Implementation Guidelines
- Next.js 15+ Standard: Use
fetchwithrevalidate: numberorcache: 'force-cache'for API calls. Useunstable_cacheor the new'use cache'(experimental) for custom data stores. - Layers: Distinguish between Data Cache (persistent across requests) and Request Memoization (React's lifecycle specific). Use
cache()from React to deduplicate fetches within a single render. - Invalidation: Use
revalidatePath('/')after mutations orrevalidateTag('tag-name')for granular cache purging. - Client Cache: Understand the Router Cache (in-memory on client) and its 30s-min lifespan. Clear it using
router.refresh(). - Static Assets: Leverage
generateStaticParamsfor pre-rendering static routes at build time. Use ISR (Incremental Static Regeneration) for content that updates periodically. - Streaming: Combine
Suspensewithfetchtriggers to prevent slow data from blocking the entire page render. - Next.js 16+: Favor
'use cache'andcacheLife()overrevalidate: numberwhere available for deterministic caching.
| Layer | Where | Control |
|---|---|---|
| Request Memoization | Server | React cache() |
| Data Cache | Server | 'use cache', revalidateTag |
| Full Route Cache | Server | Static Prerendering |
| Router Cache | Client | router.refresh() |
Implementation Details
See Cache Components & PPR for detailed key generation, closure constraints, and invalidation strategies.
Anti-Patterns
- No
unstable_cachein Next.js 16+: Use'use cache'directive withcacheLife()instead. - No
router.refresh()for server data: PreferrevalidateTag()for targeted cache busting. - No caching user-specific data at route level: Wrap personal data in
<Suspense>with'use cache'. - No long-lived cache without tags: Assign
cacheTag()for fine-grained invalidation control.
> related_skills --same-repo
> common-store-changelog
Generate user-facing release notes for the Apple App Store and Google Play Store by collecting git history, triaging user-impacting changes, and drafting store-compliant changelogs. Enforces character limits (App Store ≤4000, Google Play ≤500), tone, and bullet format. Use when generating release notes, app store changelog, play store release, what's new, or version release notes for any mobile app. (triggers: generate changelog, app store notes, play store release, what's new, release notes, ve
> golang-tooling
Go developer toolchain — gopls LSP diagnostics, linting, formatting, and vet. Use when setting up Go tooling, running linters, or integrating gopls with Claude Code. (triggers: gopls, golangci-lint, golangci.yml, go vet, goimports, staticcheck, go tooling, go lint)
> common-ui-design
Design distinctive, production-grade frontend UI with bold aesthetic choices. Use when building web components, pages, interfaces, dashboards, or applications in any framework (React, Next.js, Angular, Vue, HTML/CSS). (triggers: build a page, create a component, design a dashboard, landing page, UI for, build a layout, make it look good, improve the design, build UI, create interface, design screen)
> common-owasp
OWASP Top 10 audit checklist for Web Applications (2021) and APIs (2023). Load during any security review, PR review, or codebase audit touching web, mobile backend, or API code. (triggers: security review, OWASP, broken access control, IDOR, BOLA, injection, broken auth, API review, authorization, access control)