UNPKG

@fortedigital/nextjs-cache-handler

Version:
69 lines (66 loc) 2.21 kB
import { CacheHandler } from '../handlers/cache-handler.js'; import 'next/dist/server/lib/incremental-cache'; import '../handlers/cache-handler.types.js'; import 'next/dist/server/lib/incremental-cache/file-system-cache'; import 'next/dist/server/response-cache/types'; type CacheHandlerType = typeof CacheHandler; /** * Options for the `registerInitialCache` instrumentation. */ type RegisterInitialCacheOptions = { /** * Whether to populate the cache with fetch calls. * * @default true */ fetch?: boolean; /** * Whether to populate the cache with pre-rendered pages. * * @default true */ pages?: boolean; /** * Whether to populate the cache with routes. * * @default true */ routes?: boolean; }; /** * Populates the cache with the initial data. * * By default, it includes the following: * - Pre-rendered pages * - Routes * - Fetch calls * * @param CacheHandler - The configured CacheHandler class, not an instance. * * @param [options={}] - Options for the instrumentation. See {@link RegisterInitialCacheOptions}. * * @param [options.fetch=true] - Whether to populate the cache with fetch calls. * * @param [options.pages=true] - Whether to populate the cache with pre-rendered pages. * * @param [options.routes=true] - Whether to populate the cache with routes. * * @example file: `instrumentation.ts` * * ```js * export async function register() { * if (process.env.NEXT_RUNTIME === 'nodejs') { * const { registerInitialCache } = await import('@fortedigital/nextjs-cache-handler/instrumentation'); * // Assuming that your CacheHandler configuration is in the root of the project and the instrumentation is in the src directory. * // Please adjust the path accordingly. * // CommonJS CacheHandler configuration is also supported. * const CacheHandler = (await import('../cache-handler.mjs')).default; * await registerInitialCache(CacheHandler); * } * } * ``` * * */ declare function registerInitialCache(CacheHandler: CacheHandlerType, options?: RegisterInitialCacheOptions): Promise<void>; export { type RegisterInitialCacheOptions, registerInitialCache };