Communitygithub.com

ComeOnOliver/skillshub

Next.js 中的四级缓存架构。在配置请求记忆、数据缓存、全路由缓存或路由缓存时使用。

skillshub 是什么?

此技能详细介绍了 Next.js 的四种缓存层:请求记忆化(React 生命周期内去重)、数据缓存(跨请求持久化)、全路由缓存(静态预渲染)以及路由器缓存(客户端内存)。它帮助开发者避免陈旧数据问题,并针对不同场景(如 API 调用、自定义数据存储、客户端导航)提供最佳实践。技能重点介绍了 Next.js 15+ 中 `fetch` 的 `revalidate` 和 `cache` 参数、`unstable_cache` 以及实验性的 `'use cache'` 指令;同时涵盖了通过 `revalidatePath` 和 `revalidateTag` 进行缓存失效的策略。此外,还包括 `generateStaticParams` 预渲染、增量静态再生 (ISR)、流式渲染与 `Suspense`、以及 Next.js 16+ 中推荐的 `'use cache'` + `cacheLife()` 组合。技能适用于所有 Next.js 版本,尤其关注 15+ 和 16+ 的特性,并指出了常见反模式(如在 v16+ 中避免 `unstable_cache`、避免为服务器数据使用 `router.refresh()` 等)。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/HoangNguyen0403/agent-skills-standard/nextjs-caching

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

缓存架构

优先级: P1(高)

Next.js 有 4 种不同的缓存层。理解它们可以防止出现数据陈旧错误。

实施指南

  • Next.js 15+ 标准:对于 API 调用,使用 fetch + revalidate: number 或 cache: 'force-cache'。对于自定义数据存储,使用 unstable_cache 或新的 'use cache'(实验性)。
  • 层:区分数据缓存(跨请求持久化)和请求记忆化(React 生命周期特定)。使用 React 的 cache() 在单个渲染中去重 fetch 调用。
  • 失效:在数据变更后使用 revalidatePath('/'),或使用 revalidateTag('tag-name') 进行细粒度缓存清除。
  • 客户端缓存:理解路由器缓存(客户端内存中的缓存)及其 30 秒至分钟的生存期。使用 router.refresh() 清除它。
  • 静态资源:利用 generateStaticParams 在构建时预渲染静态路由。对于定期更新的内容,使用 ISR(增量静态再生)。
  • 流式渲染:将 Suspense 与 fetch 触发相结合,防止慢数据阻塞整个页面渲染。
  • Next.js 16+:在可用的情况下,优先使用 'use cache' 和 cacheLife() 而非 revalidate: number,以实现确定性缓存。
层位置控制
请求记忆化服务器React cache()
数据缓存服务器'use cache', revalidateTag
全路由缓存服务器静态预渲染
路由器缓存客户端router.refresh()

实施细节

请参阅 缓存组件和 PPR 了解详细的键生成、闭包约束和失效策略。

反模式

  • Next.js 16+ 中不要使用 unstable_cache:应改用 'use cache' 指令 + cacheLife()。
  • 不要对服务器数据使用 router.refresh():优先使用 revalidateTag() 进行有目标的缓存清除。
  • 不要在路由级别缓存用户特定数据:将个人数据包裹在 <Suspense> 中并使用 'use cache'。
  • 不要使用没有标签的长期缓存:分配 cacheTag() 以实现细粒度失效控制。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相关技能