perf(cache): size-capped SQLite cache handler instead of per-file ISR cache

The default Next.js cache writes one file per rendered page and per fetch
and never evicts. With on-demand movie/person/tv pages and crawlers walking
the sitemap, it grew to ~3.7M files (~80 GB) in 5 days, and deleting them
loaded the whole server.

cache-handler.js keeps the ISR and fetch cache in a single SQLite file
(node:sqlite, no native dependency) and evicts the least recently used
entries once it passes NEXT_CACHE_MAX_MB (default 5 GB), so the cache stays
bounded with no cleanup job. The file lives in the container, so each deploy
starts with a fresh cache that never serves pages from an older build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ubuntuandClaude Opus 5.5 committed 2026-10-05 07:00:35 +00:00
1 parent 322f171d88
commit c2947bed32
2 files changed
+167

No files matched your search

+3
View File
@@ -1,6 +1,9 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
// ISR/fetch cache in one size-capped SQLite file instead of millions of files, see cache-handler.js
cacheHandler: require.resolve('./cache-handler.js'),
cacheMaxMemorySize: 0,
experimental: {
optimizeCss: true,
staleTimes: {