docs/01-app/03-api-reference/05-config/01-next-config-js/cacheMaxMemorySize.mdx
cacheMaxMemorySize sets the size, in bytes, of the in-memory cache each Next.js server instance keeps. It defaults to 50 MB.
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
cacheMaxMemorySize: 50 * 1024 * 1024, // 50 MB, the default
}
export default nextConfig
/** @type {import('next').NextConfig} */
const nextConfig = {
cacheMaxMemorySize: 50 * 1024 * 1024, // 50 MB, the default
}
module.exports = nextConfig
The option sizes two separate caches:
0 when adopting a custom cacheHandler, so reads go to your store rather than a per-instance copy.'use cache'. If you register your own handler through cacheHandlers, that handler manages its own memory and this option no longer applies to it.Setting cacheMaxMemorySize: 0 disables both in-memory caches. It is also a way to mimic how use cache behaves in a serverless environment, where entries rarely survive between requests.
Good to know:
next devkeeps its own in-memory cache regardless of this option, so reloads stay fast. Production honors the configured value exactly.