diff --git a/docs/02-app/01-building-your-application/09-deploying/index.mdx b/docs/02-app/01-building-your-application/09-deploying/index.mdx index db0d4a0ea958e..c54bb181bad90 100644 --- a/docs/02-app/01-building-your-application/09-deploying/index.mdx +++ b/docs/02-app/01-building-your-application/09-deploying/index.mdx @@ -146,10 +146,8 @@ To configure the ISR/Data Cache location when self-hosting, you can configure a ```jsx filename="next.config.js" module.exports = { - experimental: { - incrementalCacheHandlerPath: require.resolve('./cache-handler.js'), - isrMemoryCacheSize: 0, // disable default in-memory caching - }, + cacheHandler: require.resolve('./cache-handler.js'), + cacheMaxMemorySize: 0, // disable default in-memory caching } ``` diff --git a/docs/02-app/02-api-reference/05-next-config-js/incrementalCacheHandlerPath.mdx b/docs/02-app/02-api-reference/05-next-config-js/incrementalCacheHandlerPath.mdx index 7d8a7cc1395da..68a6fef7fe0a9 100644 --- a/docs/02-app/02-api-reference/05-next-config-js/incrementalCacheHandlerPath.mdx +++ b/docs/02-app/02-api-reference/05-next-config-js/incrementalCacheHandlerPath.mdx @@ -1,41 +1,19 @@ --- -title: incrementalCacheHandlerPath -description: Configure the Next.js cache used for storing and revalidating data. +title: Custom Next.js Cache Handler +nav_title: cacheHandler +description: Configure the Next.js cache used for storing and revalidating data to use any external service like Redis, Memcached, or others. --- -In Next.js, the [default cache handler](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating) uses the filesystem cache. This requires no configuration, however, you can customize the cache handler by using the `incrementalCacheHandlerPath` field in `next.config.js`. +In Next.js, the [default cache handler](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating) for the Pages and App Router uses the filesystem cache. This requires no configuration, however, you can customize the cache handler by using the `cacheHandler` field in `next.config.js`. ```js filename="next.config.js" module.exports = { - experimental: { - incrementalCacheHandlerPath: require.resolve('./cache-handler.js'), - }, + cacheHandler: require.resolve('./cache-handler.js'), + cacheMaxMemorySize: 0, // disable default in-memory caching } ``` -Here's an example of a custom cache handler: - -```js filename="cache-handler.js" -const cache = new Map() - -module.exports = class CacheHandler { - constructor(options) { - this.options = options - this.cache = {} - } - - async get(key) { - return cache.get(key) - } - - async set(key, data) { - cache.set(key, { - value: data, - lastModified: Date.now(), - }) - } -} -``` +View an example of a [custom cache handler](/docs/app/building-your-application/deploying#configuring-caching) and learn more about implementation. ## API Reference @@ -55,6 +33,7 @@ Returns the cached value or `null` if not found. | --------- | -------------- | -------------------------------- | | `key` | `string` | The key to store the data under. | | `data` | Data or `null` | The data to be cached. | +| `ctx` | `{ tags: [] }` | The cache tags provided. | Returns `Promise`. @@ -65,3 +44,16 @@ Returns `Promise`. | `tag` | `string` | The cache tag to revalidate. | Returns `Promise`. Learn more about [revalidating data](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating) or the [`revalidateTag()`](/docs/app/api-reference/functions/revalidateTag) function. + +**Good to know:** + +- `revalidatePath` is a convenience layer on top of cache tags. Calling `revalidatePath` will call your `revalidateTag` function, which you can then choose if you want to tag cache keys based on the path. + +## Version History + +| Version | Changes | +| --------- | ------------------------------------------------------------------------ | +| `v14.1.0` | Renamed `cacheHandler` is stable. | +| `v13.4.0` | `incrementalCacheHandlerPath` (experimental) supports `revalidateTag`. | +| `v13.4.0` | `incrementalCacheHandlerPath` (experimental) supports standalone output. | +| `v12.2.0` | `incrementalCacheHandlerPath` (experimental) is added. | diff --git a/docs/03-pages/01-building-your-application/03-data-fetching/04-incremental-static-regeneration.mdx b/docs/03-pages/01-building-your-application/03-data-fetching/04-incremental-static-regeneration.mdx index 495fd65f4de4a..bb2b6aedec0b2 100644 --- a/docs/03-pages/01-building-your-application/03-data-fetching/04-incremental-static-regeneration.mdx +++ b/docs/03-pages/01-building-your-application/03-data-fetching/04-incremental-static-regeneration.mdx @@ -1,6 +1,6 @@ --- -title: Incremental Static Regeneration -description: 'Learn how to create or update static pages at runtime with Incremental Static Regeneration.' +title: Incremental Static Regeneration (ISR) +description: Learn how to create or update static pages at runtime with Incremental Static Regeneration. ---
@@ -169,29 +169,13 @@ export async function getStaticProps() { Incremental Static Regeneration (ISR) works on [self-hosted Next.js sites](/docs/pages/building-your-application/deploying#self-hosting) out of the box when you use `next start`. -You can use this approach when deploying to container orchestrators such as [Kubernetes](https://kubernetes.io/) or [HashiCorp Nomad](https://www.nomadproject.io/). By default, generated assets will be stored in-memory on each pod. This means that each pod will have its own copy of the static files. Stale data may be shown until that specific pod is hit by a request. - -To ensure consistency across all pods, you can disable in-memory caching. This will inform the Next.js server to only leverage assets generated by ISR in the file system. - -You can use a shared network mount in your Kubernetes pods (or similar setup) to reuse the same file-system cache between different containers. By sharing the same mount, the `.next` folder which contains the `next/image` cache will also be shared and re-used. - -To disable in-memory caching, set `isrMemoryCacheSize` to `0` in your `next.config.js` file: - -```js filename="next.config.js" -module.exports = { - experimental: { - // Defaults to 50MB - isrMemoryCacheSize: 0, // cache size in bytes - }, -} -``` - -> **Good to know**: You might need to consider a race condition between multiple pods trying to update the cache at the same time, depending on how your shared mount is configured. +Learn more about [self-hosting Next.js](/docs/pages/building-your-application/deploying#self-hosting). ## Version History | Version | Changes | | --------- | --------------------------------------------------------------------------------------- | +| `v14.1.0` | Custom `cacheHandler` is stable. | | `v12.2.0` | On-Demand ISR is stable | | `v12.1.0` | On-Demand ISR added (beta). | | `v12.0.0` | [Bot-aware ISR fallback](https://nextjs.org/blog/next-12#bot-aware-isr-fallback) added. | diff --git a/packages/next/src/build/collect-build-traces.ts b/packages/next/src/build/collect-build-traces.ts index a0e6398653a7c..aa26f34ffd28e 100644 --- a/packages/next/src/build/collect-build-traces.ts +++ b/packages/next/src/build/collect-build-traces.ts @@ -239,16 +239,16 @@ export async function collectBuildTraces({ )), ] - const { incrementalCacheHandlerPath } = config.experimental + const { cacheHandler } = config // ensure we trace any dependencies needed for custom // incremental cache handler - if (incrementalCacheHandlerPath) { + if (cacheHandler) { sharedEntriesSet.push( require.resolve( - path.isAbsolute(incrementalCacheHandlerPath) - ? incrementalCacheHandlerPath - : path.join(dir, incrementalCacheHandlerPath) + path.isAbsolute(cacheHandler) + ? cacheHandler + : path.join(dir, cacheHandler) ) ) } diff --git a/packages/next/src/build/entries.ts b/packages/next/src/build/entries.ts index 45567f8f43cd2..db4c2c6126dbe 100644 --- a/packages/next/src/build/entries.ts +++ b/packages/next/src/build/entries.ts @@ -414,8 +414,7 @@ export function getEdgeServerEntry(opts: { pagesType: opts.pagesType, appDirLoader: Buffer.from(opts.appDirLoader || '').toString('base64'), sriEnabled: !opts.isDev && !!opts.config.experimental.sri?.algorithm, - incrementalCacheHandlerPath: - opts.config.experimental.incrementalCacheHandlerPath, + cacheHandler: opts.config.cacheHandler, preferredRegion: opts.preferredRegion, middlewareConfig: Buffer.from( JSON.stringify(opts.middlewareConfig || {}) diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index c51656cd5ac11..056edc50cad77 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -1245,7 +1245,7 @@ export default async function build( PAGES_MANIFEST ) - const { incrementalCacheHandlerPath } = config.experimental + const { cacheHandler } = config const requiredServerFilesManifest = nextBuildSpan .traceChild('generate-required-server-files') @@ -1260,12 +1260,12 @@ export default async function build( compress: false, } : {}), + cacheHandler: cacheHandler + ? path.relative(distDir, cacheHandler) + : config.cacheHandler, experimental: { ...config.experimental, trustHostHeader: ciEnvironment.hasNextSupport, - incrementalCacheHandlerPath: incrementalCacheHandlerPath - ? path.relative(distDir, incrementalCacheHandlerPath) - : undefined, // @ts-expect-error internal field TODO: fix this, should use a separate mechanism to pass the info. isExperimentalCompile: isCompileMode, @@ -1523,11 +1523,11 @@ export default async function build( if (config.experimental.staticWorkerRequestDeduping) { let CacheHandler - if (incrementalCacheHandlerPath) { + if (cacheHandler) { CacheHandler = interopDefault( - await import( - formatDynamicImportPath(dir, incrementalCacheHandlerPath) - ).then((mod) => mod.default || mod) + await import(formatDynamicImportPath(dir, cacheHandler)).then( + (mod) => mod.default || mod + ) ) } @@ -1542,7 +1542,7 @@ export default async function build( : config.experimental.isrFlushToDisk, serverDistDir: path.join(distDir, 'server'), fetchCacheKeyPrefix: config.experimental.fetchCacheKeyPrefix, - maxMemoryCacheSize: config.experimental.isrMemoryCacheSize, + maxMemoryCacheSize: config.cacheMaxMemorySize, getPrerenderManifest: () => ({ version: -1 as any, // letting us know this doesn't conform to spec routes: {}, @@ -1840,13 +1840,11 @@ export default async function build( pageRuntime, edgeInfo, pageType, - incrementalCacheHandlerPath: - config.experimental.incrementalCacheHandlerPath, + cacheHandler: config.cacheHandler, isrFlushToDisk: ciEnvironment.hasNextSupport ? false : config.experimental.isrFlushToDisk, - maxMemoryCacheSize: - config.experimental.isrMemoryCacheSize, + maxMemoryCacheSize: config.cacheMaxMemorySize, nextConfigOutput: config.output, ppr: config.experimental.ppr === true, }) diff --git a/packages/next/src/build/utils.ts b/packages/next/src/build/utils.ts index a114b48bb275e..91818fd3d717e 100644 --- a/packages/next/src/build/utils.ts +++ b/packages/next/src/build/utils.ts @@ -1304,7 +1304,7 @@ export async function buildAppStaticPaths({ configFileName, generateParams, isrFlushToDisk, - incrementalCacheHandlerPath, + cacheHandler, requestHeaders, maxMemoryCacheSize, fetchCacheKeyPrefix, @@ -1315,10 +1315,10 @@ export async function buildAppStaticPaths({ page: string configFileName: string generateParams: GenerateParamsResults - incrementalCacheHandlerPath?: string distDir: string isrFlushToDisk?: boolean fetchCacheKeyPrefix?: string + cacheHandler?: string maxMemoryCacheSize?: number requestHeaders: IncrementalCache['requestHeaders'] ppr: boolean @@ -1328,11 +1328,11 @@ export async function buildAppStaticPaths({ let CacheHandler: any - if (incrementalCacheHandlerPath) { + if (cacheHandler) { CacheHandler = interopDefault( - await import( - formatDynamicImportPath(dir, incrementalCacheHandlerPath) - ).then((mod) => mod.default || mod) + await import(formatDynamicImportPath(dir, cacheHandler)).then( + (mod) => mod.default || mod + ) ) } @@ -1483,7 +1483,7 @@ export async function isPageStatic({ originalAppPath, isrFlushToDisk, maxMemoryCacheSize, - incrementalCacheHandlerPath, + cacheHandler, ppr, }: { dir: string @@ -1501,7 +1501,7 @@ export async function isPageStatic({ originalAppPath?: string isrFlushToDisk?: boolean maxMemoryCacheSize?: number - incrementalCacheHandlerPath?: string + cacheHandler?: string nextConfigOutput: 'standalone' | 'export' ppr: boolean }): Promise<{ @@ -1667,7 +1667,7 @@ export async function isPageStatic({ requestHeaders: {}, isrFlushToDisk, maxMemoryCacheSize, - incrementalCacheHandlerPath, + cacheHandler, ppr, ComponentMod, })) diff --git a/packages/next/src/build/webpack/loaders/next-edge-ssr-loader/index.ts b/packages/next/src/build/webpack/loaders/next-edge-ssr-loader/index.ts index b4dc9bd0700c4..e0f0728e8eaad 100644 --- a/packages/next/src/build/webpack/loaders/next-edge-ssr-loader/index.ts +++ b/packages/next/src/build/webpack/loaders/next-edge-ssr-loader/index.ts @@ -24,7 +24,7 @@ export type EdgeSSRLoaderQuery = { appDirLoader?: string pagesType: PAGE_TYPES sriEnabled: boolean - incrementalCacheHandlerPath?: string + cacheHandler?: string preferredRegion: string | string[] | undefined middlewareConfig: string serverActions?: { @@ -76,7 +76,7 @@ const edgeSSRLoader: webpack.LoaderDefinitionFunction = appDirLoader: appDirLoaderBase64, pagesType, sriEnabled, - incrementalCacheHandlerPath, + cacheHandler, preferredRegion, middlewareConfig: middlewareConfigBase64, serverActions, @@ -158,7 +158,7 @@ const edgeSSRLoader: webpack.LoaderDefinitionFunction = : JSON.stringify(serverActions), }, { - incrementalCacheHandler: incrementalCacheHandlerPath ?? null, + incrementalCacheHandler: cacheHandler ?? null, } ) } else { @@ -187,7 +187,7 @@ const edgeSSRLoader: webpack.LoaderDefinitionFunction = }, { userland500Page: userland500Path, - incrementalCacheHandler: incrementalCacheHandlerPath ?? null, + incrementalCacheHandler: cacheHandler ?? null, } ) } diff --git a/packages/next/src/export/helpers/create-incremental-cache.ts b/packages/next/src/export/helpers/create-incremental-cache.ts index 85b943689331f..abc768da13b35 100644 --- a/packages/next/src/export/helpers/create-incremental-cache.ts +++ b/packages/next/src/export/helpers/create-incremental-cache.ts @@ -8,8 +8,8 @@ import { interopDefault } from '../../lib/interop-default' import { formatDynamicImportPath } from '../../lib/format-dynamic-import-path' export async function createIncrementalCache({ - incrementalCacheHandlerPath, - isrMemoryCacheSize, + cacheHandler, + cacheMaxMemorySize, fetchCacheKeyPrefix, distDir, dir, @@ -17,8 +17,8 @@ export async function createIncrementalCache({ experimental, flushToDisk, }: { - incrementalCacheHandlerPath?: string - isrMemoryCacheSize?: number + cacheHandler?: string + cacheMaxMemorySize?: number fetchCacheKeyPrefix?: string distDir: string dir: string @@ -28,11 +28,11 @@ export async function createIncrementalCache({ }) { // Custom cache handler overrides. let CacheHandler: any - if (incrementalCacheHandlerPath) { + if (cacheHandler) { CacheHandler = interopDefault( - await import( - formatDynamicImportPath(dir, incrementalCacheHandlerPath) - ).then((mod) => mod.default || mod) + await import(formatDynamicImportPath(dir, cacheHandler)).then( + (mod) => mod.default || mod + ) ) } @@ -41,7 +41,7 @@ export async function createIncrementalCache({ requestHeaders: {}, flushToDisk, fetchCache: true, - maxMemoryCacheSize: isrMemoryCacheSize, + maxMemoryCacheSize: cacheMaxMemorySize, fetchCacheKeyPrefix, getPrerenderManifest: () => ({ version: 4, diff --git a/packages/next/src/export/index.ts b/packages/next/src/export/index.ts index c4d0516ec9e51..b07ca09bdc863 100644 --- a/packages/next/src/export/index.ts +++ b/packages/next/src/export/index.ts @@ -701,11 +701,10 @@ export async function exportAppImpl( parentSpanId: pageExportSpan.getId(), httpAgentOptions: nextConfig.httpAgentOptions, debugOutput: options.debugOutput, - isrMemoryCacheSize: nextConfig.experimental.isrMemoryCacheSize, + cacheMaxMemorySize: nextConfig.cacheMaxMemorySize, fetchCache: true, fetchCacheKeyPrefix: nextConfig.experimental.fetchCacheKeyPrefix, - incrementalCacheHandlerPath: - nextConfig.experimental.incrementalCacheHandlerPath, + cacheHandler: nextConfig.cacheHandler, enableExperimentalReact: needsExperimentalReact(nextConfig), enabledDirectories, }) diff --git a/packages/next/src/export/types.ts b/packages/next/src/export/types.ts index 5244ed53d3ce1..26cdef3cc79a3 100644 --- a/packages/next/src/export/types.ts +++ b/packages/next/src/export/types.ts @@ -53,9 +53,9 @@ export interface ExportPageInput { parentSpanId: any httpAgentOptions: NextConfigComplete['httpAgentOptions'] debugOutput?: boolean - isrMemoryCacheSize?: NextConfigComplete['experimental']['isrMemoryCacheSize'] + cacheMaxMemorySize?: NextConfigComplete['cacheMaxMemorySize'] fetchCache?: boolean - incrementalCacheHandlerPath?: string + cacheHandler?: string fetchCacheKeyPrefix?: string nextConfigOutput?: NextConfigComplete['output'] enableExperimentalReact?: boolean diff --git a/packages/next/src/export/worker.ts b/packages/next/src/export/worker.ts index 97b0002e35499..1b2aa2a88c8a1 100644 --- a/packages/next/src/export/worker.ts +++ b/packages/next/src/export/worker.ts @@ -60,10 +60,10 @@ async function exportPageImpl( optimizeCss, disableOptimizedLoading, debugOutput = false, - isrMemoryCacheSize, + cacheMaxMemorySize, fetchCache, fetchCacheKeyPrefix, - incrementalCacheHandlerPath, + cacheHandler, enableExperimentalReact, ampValidatorPath, trailingSlash, @@ -222,8 +222,8 @@ async function exportPageImpl( const incrementalCache = isAppDir && fetchCache ? await createIncrementalCache({ - incrementalCacheHandlerPath, - isrMemoryCacheSize, + cacheHandler, + cacheMaxMemorySize, fetchCacheKeyPrefix, distDir, dir, diff --git a/packages/next/src/server/config-schema.ts b/packages/next/src/server/config-schema.ts index 345b1a7bb3dfd..4f44f041c4c54 100644 --- a/packages/next/src/server/config-schema.ts +++ b/packages/next/src/server/config-schema.ts @@ -117,6 +117,8 @@ export const configSchema: zod.ZodType = z.lazy(() => analyticsId: z.string().optional(), assetPrefix: z.string().optional(), basePath: z.string().optional(), + cacheHandler: z.string().min(1).optional(), + cacheMaxMemorySize: z.number().optional(), cleanDistDir: z.boolean().optional(), compiler: z .strictObject({ @@ -266,9 +268,7 @@ export const configSchema: zod.ZodType = z.lazy(() => forceSwcTransforms: z.boolean().optional(), fullySpecified: z.boolean().optional(), gzipSize: z.boolean().optional(), - incrementalCacheHandlerPath: z.string().optional(), isrFlushToDisk: z.boolean().optional(), - isrMemoryCacheSize: z.number().optional(), largePageDataBytes: z.number().optional(), manualClientBasePath: z.boolean().optional(), middlewarePrefetch: z.enum(['strict', 'flexible']).optional(), diff --git a/packages/next/src/server/config-shared.ts b/packages/next/src/server/config-shared.ts index 9b9b2da41fb6b..4e4d18e836d9b 100644 --- a/packages/next/src/server/config-shared.ts +++ b/packages/next/src/server/config-shared.ts @@ -178,8 +178,6 @@ export interface ExperimentalConfig { optimisticClientCache?: boolean middlewarePrefetch?: 'strict' | 'flexible' manualClientBasePath?: boolean - // custom path to a cache handler to use - incrementalCacheHandlerPath?: string disablePostcssPresetEnv?: boolean swcMinify?: boolean cpus?: number @@ -203,12 +201,6 @@ export interface ExperimentalConfig { gzipSize?: boolean craCompat?: boolean esmExternals?: boolean | 'loose' - /** - * In-memory cache size in bytes. - * - * If `isrMemoryCacheSize: 0` disables in-memory caching. - */ - isrMemoryCacheSize?: number fullySpecified?: boolean urlImports?: NonNullable['buildHttp'] outputFileTracingRoot?: string @@ -507,6 +499,21 @@ export interface NextConfig extends Record { */ assetPrefix?: string + /** + * The default cache handler for the Pages and App Router uses the filesystem cache. This requires no configuration, however, you can customize the cache handler if you prefer. + * + * @see [Configuring Caching](https://nextjs.org/docs/app/building-your-application/deploying#configuring-caching) and the [API Reference](https://nextjs.org/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath). + */ + cacheHandler?: string | undefined + + /** + * Configure the in-memory cache size in bytes. Defaults to 50 MB. + * If `cacheMaxMemorySize: 0`, this disables in-memory caching entirely. + * + * @see [Configuring Caching](https://nextjs.org/docs/app/building-your-application/deploying#configuring-caching). + */ + cacheMaxMemorySize?: number + /** * By default, `Next` will serve each file in the `pages` folder under a pathname matching the filename. * To disable this behavior and prevent routing based set this to `true`. @@ -749,6 +756,9 @@ export const defaultConfig: NextConfig = { distDir: '.next', cleanDistDir: true, assetPrefix: '', + cacheHandler: undefined, + // default to 50MB limit + cacheMaxMemorySize: 50 * 1024 * 1024, configOrigin: 'default', useFileSystemPublicRoutes: true, generateBuildId: () => null, @@ -819,9 +829,6 @@ export const defaultConfig: NextConfig = { gzipSize: true, craCompat: false, esmExternals: true, - // default to 50MB limit - isrMemoryCacheSize: 50 * 1024 * 1024, - incrementalCacheHandlerPath: undefined, fullySpecified: false, outputFileTracingRoot: process.env.NEXT_PRIVATE_OUTPUT_TRACE_ROOT || '', swcTraceProfiling: false, diff --git a/packages/next/src/server/dev/next-dev-server.ts b/packages/next/src/server/dev/next-dev-server.ts index 699f5fcc7e90e..6bebd0ea1621a 100644 --- a/packages/next/src/server/dev/next-dev-server.ts +++ b/packages/next/src/server/dev/next-dev-server.ts @@ -695,11 +695,10 @@ export default class DevServer extends Server { page, isAppPath, requestHeaders, - incrementalCacheHandlerPath: - this.nextConfig.experimental.incrementalCacheHandlerPath, + cacheHandler: this.nextConfig.cacheHandler, fetchCacheKeyPrefix: this.nextConfig.experimental.fetchCacheKeyPrefix, isrFlushToDisk: this.nextConfig.experimental.isrFlushToDisk, - maxMemoryCacheSize: this.nextConfig.experimental.isrMemoryCacheSize, + maxMemoryCacheSize: this.nextConfig.cacheMaxMemorySize, ppr: this.nextConfig.experimental.ppr === true, }) return pathsResult diff --git a/packages/next/src/server/dev/static-paths-worker.ts b/packages/next/src/server/dev/static-paths-worker.ts index 080f0cd32e665..4d0d83064c0bf 100644 --- a/packages/next/src/server/dev/static-paths-worker.ts +++ b/packages/next/src/server/dev/static-paths-worker.ts @@ -37,7 +37,7 @@ export async function loadStaticPaths({ fetchCacheKeyPrefix, maxMemoryCacheSize, requestHeaders, - incrementalCacheHandlerPath, + cacheHandler, ppr, }: { dir: string @@ -53,7 +53,7 @@ export async function loadStaticPaths({ fetchCacheKeyPrefix?: string maxMemoryCacheSize?: number requestHeaders: IncrementalCache['requestHeaders'] - incrementalCacheHandlerPath?: string + cacheHandler?: string ppr: boolean }): Promise<{ paths?: string[] @@ -105,7 +105,7 @@ export async function loadStaticPaths({ configFileName: config.configFileName, distDir, requestHeaders, - incrementalCacheHandlerPath, + cacheHandler, isrFlushToDisk, fetchCacheKeyPrefix, maxMemoryCacheSize, diff --git a/packages/next/src/server/next-server.ts b/packages/next/src/server/next-server.ts index b79b7adcac9ba..b7da975e85a56 100644 --- a/packages/next/src/server/next-server.ts +++ b/packages/next/src/server/next-server.ts @@ -308,12 +308,12 @@ export default class NextNodeServer extends BaseServer { }) { const dev = !!this.renderOpts.dev let CacheHandler: any - const { incrementalCacheHandlerPath } = this.nextConfig.experimental + const { cacheHandler } = this.nextConfig - if (incrementalCacheHandlerPath) { + if (cacheHandler) { CacheHandler = interopDefault( await dynamicImportEsmDefault( - formatDynamicImportPath(this.distDir, incrementalCacheHandlerPath) + formatDynamicImportPath(this.distDir, cacheHandler) ) ) } @@ -334,7 +334,7 @@ export default class NextNodeServer extends BaseServer { serverDistDir: this.serverDistDir, fetchCache: true, fetchCacheKeyPrefix: this.nextConfig.experimental.fetchCacheKeyPrefix, - maxMemoryCacheSize: this.nextConfig.experimental.isrMemoryCacheSize, + maxMemoryCacheSize: this.nextConfig.cacheMaxMemorySize, flushToDisk: !this.minimalMode && this.nextConfig.experimental.isrFlushToDisk, getPrerenderManifest: () => this.getPrerenderManifest(), diff --git a/packages/next/src/server/web-server.ts b/packages/next/src/server/web-server.ts index fd06379379012..6a563bbc88577 100644 --- a/packages/next/src/server/web-server.ts +++ b/packages/next/src/server/web-server.ts @@ -75,7 +75,7 @@ export default class NextWebServer extends BaseServer { minimalMode: this.minimalMode, fetchCache: true, fetchCacheKeyPrefix: this.nextConfig.experimental.fetchCacheKeyPrefix, - maxMemoryCacheSize: this.nextConfig.experimental.isrMemoryCacheSize, + maxMemoryCacheSize: this.nextConfig.cacheMaxMemorySize, flushToDisk: false, CurCacheHandler: this.serverOptions.webServerConfig.incrementalCacheHandler, diff --git a/test/e2e/app-dir/app-custom-cache-handler/next.config.js b/test/e2e/app-dir/app-custom-cache-handler/next.config.js index 16c82f0775544..bf4890f9ae43f 100644 --- a/test/e2e/app-dir/app-custom-cache-handler/next.config.js +++ b/test/e2e/app-dir/app-custom-cache-handler/next.config.js @@ -1,6 +1,3 @@ module.exports = { - experimental: { - incrementalCacheHandlerPath: - process.cwd() + '/' + process.env.CUSTOM_CACHE_HANDLER, - }, + cacheHandler: process.cwd() + '/' + process.env.CUSTOM_CACHE_HANDLER, } diff --git a/test/e2e/app-dir/app-static/next.config.js b/test/e2e/app-dir/app-static/next.config.js index 57153652e47f0..92fbed1ddc084 100644 --- a/test/e2e/app-dir/app-static/next.config.js +++ b/test/e2e/app-dir/app-static/next.config.js @@ -3,9 +3,7 @@ module.exports = { logging: { fetches: {}, }, - experimental: { - incrementalCacheHandlerPath: process.env.CUSTOM_CACHE_HANDLER, - }, + cacheHandler: process.env.CUSTOM_CACHE_HANDLER, rewrites: async () => { return { diff --git a/test/production/standalone-mode/required-server-files/required-server-files-app.test.ts b/test/production/standalone-mode/required-server-files/required-server-files-app.test.ts index 1f23cd0375c72..59a39468af827 100644 --- a/test/production/standalone-mode/required-server-files/required-server-files-app.test.ts +++ b/test/production/standalone-mode/required-server-files/required-server-files-app.test.ts @@ -38,9 +38,8 @@ describe('required server files app router', () => { '.env.production': new FileRef(join(__dirname, '.env.production')), }, nextConfig: { - experimental: { - incrementalCacheHandlerPath: './cache-handler.js', - }, + cacheHandler: './cache-handler.js', + cacheMaxMemorySize: 0, eslint: { ignoreDuringBuilds: true, }, diff --git a/test/production/standalone-mode/required-server-files/required-server-files-ppr.test.ts b/test/production/standalone-mode/required-server-files/required-server-files-ppr.test.ts index 6bf49e7eb9676..23b48f1d9548c 100644 --- a/test/production/standalone-mode/required-server-files/required-server-files-ppr.test.ts +++ b/test/production/standalone-mode/required-server-files/required-server-files-ppr.test.ts @@ -39,8 +39,8 @@ describe('required server files app router', () => { '.env.production': new FileRef(join(__dirname, '.env.production')), }, nextConfig: { + cacheHandler: './cache-handler.js', experimental: { - incrementalCacheHandlerPath: './cache-handler.js', ppr: true, }, eslint: { diff --git a/test/production/standalone-mode/required-server-files/required-server-files.test.ts b/test/production/standalone-mode/required-server-files/required-server-files.test.ts index 7c013f85e20c7..4afd71f8dc993 100644 --- a/test/production/standalone-mode/required-server-files/required-server-files.test.ts +++ b/test/production/standalone-mode/required-server-files/required-server-files.test.ts @@ -45,9 +45,8 @@ describe('required server files', () => { '.env.production': new FileRef(join(__dirname, '.env.production')), }, nextConfig: { - experimental: { - incrementalCacheHandlerPath: './cache-handler.js', - }, + cacheHandler: './cache-handler.js', + cacheMaxMemorySize: 0, eslint: { ignoreDuringBuilds: true, }, @@ -303,14 +302,20 @@ describe('required server files', () => { ).toContain('"compress":false') }) - it('`incrementalCacheHandlerPath` should have correct path', async () => { + it('`cacheHandler` should have correct path', async () => { expect( await fs.pathExists(join(next.testDir, 'standalone/cache-handler.js')) ).toBe(true) expect( await fs.readFileSync(join(next.testDir, 'standalone/server.js'), 'utf8') - ).toContain('"incrementalCacheHandlerPath":"../cache-handler.js"') + ).toContain('"cacheHandler":"../cache-handler.js"') + }) + + it('`cacheMaxMemorySize` should be disabled by setting to 0', async () => { + expect( + await fs.readFileSync(join(next.testDir, 'standalone/server.js'), 'utf8') + ).toContain('"cacheMaxMemorySize":0') }) it('should output middleware correctly', async () => {