cacheMaxMemorySize
Configure the size of the in-memory cache that Next.js keeps in each server instance.
cacheMaxMemorySize sets the size, in bytes, of the in-memory cache each Next.js server instance keeps. It defaults to 50 MB.
The option sizes two separate caches:
- The server cache that stores prerendered pages, route handler responses, and optimized images. Set this to
0when adopting a customcacheHandler, so reads go to your store rather than a per-instance copy. - The built-in handler behind
'use cache'. If you register your own handler throughcacheHandlers, 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 dev keeps its own in-memory cache regardless of this option, so reloads stay fast. Production honors the configured value exactly.