跳到正文
TakoAPI
返回技能列表

next-cache-components

由 tuanvidev 提供

Web & Frontend Development
358下载量由 clawskills.sh 提供
0浏览量
0 个赞登录后即可为这个技能点赞
—暂无评分
你的评分

简介

Next.js 16 Cache Components - PPR, use cache directive, cacheLife, cacheTag, updateTag.

描述

该技能的功能

Next.js 16 Cache Components enable Partial Prerendering (PPR), letting you mix static, cached, and dynamic content within a single route. The `use cache` directive marks async functions or components for caching with configurable lifetimes and tag-based invalidation, replacing the older `unstable_cache()` API and `experimental.ppr` flag.

The `use cache` directive generates cache keys automatically from function arguments and closures, removing the manual key array management that `unstable_cache` required.

何时使用

  • Caching database query results with configurable TTLs
  • Building dashboards that blend static headers, cached stats, and streaming notifications
  • Invalidating specific product cache entries after an admin update
  • Migrating from unstable_cache to the use cache directive in an existing app
  • Passing user session data as props to keep cached components runtime-compliant

示例工作流

输入

User asks: How do I cache a product list and invalidate it when a product is updated?

智能体
  1. 1

    Enable cacheComponents: true in next.config.ts

  2. 2

    Add 'use cache' and cacheTag('products') to the getProducts async function

  3. 3

    Set a cache lifetime with cacheLife('hours') inside the function

  4. 4

    Call revalidateTag('products') inside a server action after the database update

输出

Product list is served from cache on subsequent requests and refreshed in the background after the next mutation

安装

clawhub install tuanvidev/next-cache-components

运行 CLI 命令,或把这段提示词粘贴到 Claude Code、Cursor、Codex 或你在用的任意编程智能体里。

链接