Demonstrating ISR and SSR using the 'use cache' directive, cacheLife, and cacheTag
Products prerendered at build time via generateStaticParams. Cached with inline cacheLife({ ... }) timings that revalidate every hour.
'use cache' directivecacheLife({ ... }) timingscacheTag for on-demand revalidationgenerateStaticParams for build-time prerenderingFully dynamic route using headers() to opt into dynamic rendering. Includes a cached sub-component that demonstrates mixing dynamic and cached content.
headers() for fully dynamic rendering'use cache'This example uses a single config flag to enable cache components:
// next.config.ts
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
cacheComponents: true,
};Invalidate cached data by tag via the API endpoint:
# Revalidate a specific product GET /api/revalidate?tag=product-1 # Revalidate all products GET /api/revalidate?tag=products # Revalidate categories GET /api/revalidate?tag=categories