> 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)

fetch
$curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/nextjs-caching?format=md"
SKILL.mdnextjs-caching

Caching Architecture

Priority: P1 (HIGH)

Next.js has 4 distinct caching layers. Understanding them prevents stale data bugs.

Workflow: Configure Caching for a Feature

  1. Choose cache strategy — SSG (force-cache), ISR (revalidate: N), or SSR (no-store).
  2. Tag cacheable fetches — Add next: { tags: ['posts'] } to fetch options.
  3. Invalidate on mutation — Call revalidateTag('posts') in Server Actions.
  4. Deduplicate requests — Wrap shared data fetches with React cache().
  5. Clear client cache — Use router.refresh() after client-side mutations.

Cache Invalidation Example

See implementation examples

Implementation Guidelines

  • Next.js 15+ Standard: Use fetch with revalidate: number or cache: 'force-cache' for API calls. Use unstable_cache or 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 or revalidateTag('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 generateStaticParams for pre-rendering static routes at build time. Use ISR (Incremental Static Regeneration) for content that updates periodically.
  • Streaming: Combine Suspense with fetch triggers to prevent slow data from blocking the entire page render.
  • Next.js 16+: Favor 'use cache' and cacheLife() over revalidate: number where available for deterministic caching.
LayerWhereControl
Request MemoizationServerReact cache()
Data CacheServer'use cache', revalidateTag
Full Route CacheServerStatic Prerendering
Router CacheClientrouter.refresh()

Implementation Details

See Cache Components & PPR for detailed key generation, closure constraints, and invalidation strategies.

Anti-Patterns

  • No unstable_cache in Next.js 16+: Use 'use cache' directive with cacheLife() instead.
  • No router.refresh() for server data: Prefer revalidateTag() 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)

┌ stats

installs/wk0
░░░░░░░░░░
github stars452
██████████
first seenMar 17, 2026
└────────────

┌ repo

HoangNguyen0403/agent-skills-standard
by HoangNguyen0403
└────────────

┌ tags

└────────────