Skip to content
Back to skills

Nextjs Caching

ASecurity

Configure Next.js cache layers, invalidation, and cache-component APIs. Use when choosing `fetch` caching, `use cache`, tags, or stale-data debugging in Next.js.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 6, 2026
ai-agentsreactnextjsdebugginggitapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned September 6, 2026

npx -y skills add FilippoDeSilva/skills --skill nextjs-caching --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Nextjs Caching?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Nextjs Caching
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/filippodesilva-nextjs-caching/badge)](https://www.skillsdirectory.com/skills/filippodesilva-nextjs-caching)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: nextjs-caching
description: Configure Next.js cache layers, invalidation, and cache-component APIs. Use when choosing `fetch` caching, `use cache`, tags, or stale-data debugging in Next.js.
license: MIT
version: 1.0.0
author: "[Filippo De Silva](https://github.com/FilippoDeSilva)"
tags:
  - nextjs
  - caching
  - cache
  - fetch
  - use-cache
  - tags
  - invalidation
  - stale-data
metadata:
  triggers:
    files:
    - '**/page.tsx'
    - '**/layout.tsx'
    - '**/action.ts'
    keywords:
    - unstable_cache
    - revalidateTag
    - Router Cache
    - Data Cache
---
# Caching Architecture

## **Priority: P1 (HIGH)**

## Decision Map

- **HTTP reads**: start with `fetch` cache controls (`force-cache`, `no-store`, `next.revalidate`, tags). For content updated a few times per day, ISR with `revalidate` is often the right default.
- **Custom function/component caching**: prefer `use cache` with `cacheLife()` and `cacheTag()` when the project uses cache components.
- **Per-render dedupe**: use React `cache()` for repeated server reads in one render pass.
- **Mutation invalidation**: `revalidateTag()` for data ownership, `revalidatePath()` for route-level refresh, `router.refresh()` for client view refresh after mutation.

## Recipe

1. **Classify the read**: static, periodically fresh, request-specific, or user-specific.
2. **Pick the narrowest cache**: request memoization before persistent cache, tag invalidation before path-wide invalidation.
3. **Tag what mutates together**: align tags with data ownership, not page names by habit.
4. **Keep personal data private**: avoid broad route caching for request-specific state.
5. **Test stale paths**: mutation -> invalidation -> refreshed UI.

## Verify

- [ ] Cache choice matches data ownership and freshness needs.
- [ ] Mutations revalidate the tags or paths they invalidate.
- [ ] User-specific data does not leak into shared cache.
- [ ] Slow reads stream behind `Suspense` instead of blocking the whole route.
- [ ] Existing code using `unstable_cache` has a migration note if cache components are now enabled.

| Layer | Where | Control |
| :---------------------- | :----- | :----------------------------- |
| **Request Memoization** | Server render | React `cache()` |
| **Data Cache** | Server | `fetch`, `use cache`, tags |
| **Full Route Cache** | Server | static rendering / revalidation |
| **Router Cache** | Client | `router.refresh()` |

## Anti-Patterns

- **No shared cache for personal data**: request-specific state needs a private strategy or no-store path.
- **No path-wide invalidation by habit**: prefer tags when data ownership is narrower.
- **No mutation without revalidation**: stale writes are correctness bugs.
- **No cache folklore**: verify with official cache docs for the project's enabled features.

## References

- [Framework Map](../references/framework-map.md)
- [Cache Components & PPR](references/CACHE_COMPONENTS.md)
- [Implementation Examples](references/implementation.md)

Files in this skill

  • SKILL.md2.9 KB
  • evals/evals.json2 KB
  • references/CACHE_COMPONENTS.md1.8 KB
  • references/implementation.md482 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.