Welcome to the Next.js 16 + Cache Components workshop! Learn how to migrate from Next.js 15 to Next.js 16's new caching features with cache components.
- Node.js 18+ installed
- Basic knowledge of Next.js App Router
- Understanding of React Server Components
# Install dependencies
pnpm install
# Run development server
pnpm dev
# Visit http://localhost:3000The blog application currently uses:
export const dynamic = 'force-dynamic'for the blog pageexport const dynamic = 'force-static'for the homepage- Mocked data with simulated API delays
Check the console to see API calls being logged.
Update to Next.js 16 and enable new caching features.
- Update
package.json:
"next": "^16.0.0"- Configure
next.config.ts:
const nextConfig = {
cacheComponents: true,
};- Run
pnpm install
Migrate home page to use "use cache" directive. Remember to keep the original revalidation time of 60 seconds.
Migrate the blog page to use "use cache". Currently the entire page is dynamic because results are dynamic. Find a way of making the categories and layout static while keeping the posts dynamic.
Create a fully static blog post page that uses cacheTag to set a tag with the blog post id.
Create a secured route to revalidate the cache of a given tag using revalidateTag.
Add a dynamic section to the end of the blog post page to show the featured posts.
- Show the active category in the
category-filtercomponent. - Create a custom cache profile in
next.config.tsand use it. - Deploy the application and verify everything works.
Happy coding! 🚀