How to use next-cache-inspector
Learn how to scan, analyze, and optimize your Next.js App Router caching strategy.
Quick Start
npx next-cache-inspector --dir ./my-app
# or
npm install -g next-cache-inspector
next-cache-inspector --dir ./my-appThe dashboard will open at http://localhost:4242
Inspector Views
Dashboard
Get a high-level overview of your project with key metrics, route type distribution, and recent activity.
Topology
Visualize your app directory structure as an interactive graph. See how routes and layouts connect.
Tags
Browse all cache tags used across your application. See which routes use each tag and how they're invalidated.
Flow
Understand the data flow between revalidators, tags, and routes. Spot invalidation chains at a glance.
Fetches
Review every fetch() call in your application with cache settings, revalidation periods, and tags.
Rules
Catch caching anti-patterns and misconfigurations before they cause issues in production.
CLI Options
Watch for file changes and auto-rescan
next-cache-inspector --dir . --watch
Export report as HTML or JSON
next-cache-inspector --dir . --export html
Remove temp directories and cache files
next-cache-inspector --dir . --clean
Change the dashboard server port
next-cache-inspector --dir . --port 3000
Watch Mode
Automatically rescan your project when files change. Perfect for development.
npx next-cache-inspector --dir . --watchExport Reports
Generate shareable HTML reports or JSON exports for CI/CD integration.
next-cache-inspector --dir . --export html
next-cache-inspector --dir . --export json
Best Practices
Use cache tags consistently
Tag your fetch calls so you can revalidate them precisely instead of purging entire route caches.
Set appropriate revalidate values
ISR routes should have a sensible revalidate period. Avoid mixing static and dynamic on the same route without understanding the implications.
Review anti-patterns regularly
The Rules view highlights potential issues. Address warnings early to prevent cache-related bugs.
Monitor fetch cache settings
Explicitly set cache and revalidate in fetch calls. Relying on defaults can lead to unexpected behavior across Next.js versions.
