caching

Implement Next.js App Router caching with the 'use cache' directive.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/perimetre/ai-toolkit --skill caching-perimetre
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: caching
Source: https://github.com/perimetre/ai-toolkit/tree/main/plugins/perimetre-apps/skills/caching
Command: npx skills add https://github.com/perimetre/ai-toolkit --skill caching-perimetre

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill guides developers to implement modern caching strategies in Next.js App Router to maximize performance, reduce server load, and ensure fresh content.

Core Features & Use Cases

  • Implement data and route caching using the Next.js "use cache" directive for server components and functions.
  • Use cacheLife and cacheTag to control lifecycles and invalidate cached data with tags across pages and APIs.
  • Combine SSG, ISR, and route-level revalidation to achieve fast initial loads with up-to-date content across dynamic routes.

Quick Start

Set up a Next.js route that caches data with a colocated function using "use cache" and configure revalidate and tags to enable automatic background updates.

Frequently Asked Questions about caching

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement Next.js App Router caching for server components and API routes?

Next.js App Router caching is implemented using the 'use cache' directive for server components and functions. This approach applies time-based revalidation and tag-based invalidation across data-fetching, server components, and API routes to optimize performance.

When should I use cacheLife and cacheTag for ISR and SSG in Next.js?

Use cacheLife and cacheTag in Next.js 16+ when you need fine-grained control over cached data lifecycles and on-demand invalidation. cacheLife manages time-based revalidation, while cacheTag enables targeted invalidation across pages and APIs.

Does the 'use cache' directive work with colocated caching patterns in Next.js 16+?

Yes, the 'use cache' directive supports colocated caching patterns in Next.js 16+. You can set up routes that cache data with colocated functions, configuring revalidate and tags to enable automatic background updates for SSG and ISR.

What is the best way to combine SSG and ISR for dynamic routes in Next.js?

Combining SSG and ISR in Next.js involves using route-level revalidation alongside the 'use cache' directive. This strategy achieves fast initial loads with up-to-date content across dynamic routes by applying cacheLife and revalidateTag APIs.

Why does Next.js tag-based invalidation require revalidateTag for cached data?

Tag-based invalidation requires revalidateTag to manually purge cached data associated with specific cacheTag identifiers. This ensures that when underlying data changes, the cached server component or API route responses are accurately updated across the application.