UNPKG

@fortedigital/nextjs-cache-handler

Version:
75 lines (71 loc) 3.4 kB
import { CacheHandler as CacheHandler$1 } from 'next/dist/server/lib/incremental-cache'; import { OnCreationHook, FileSystemCacheContext, CacheHandlerParametersGet, CacheHandlerValue, CacheHandlerParametersSet, Revalidate, CacheHandlerParametersRevalidateTag } from './cache-handler.types.js'; import { GetIncrementalFetchCacheContext, GetIncrementalResponseCacheContext } from 'next/dist/server/response-cache/types'; import 'next/dist/server/lib/incremental-cache/file-system-cache'; declare class CacheHandler implements CacheHandler$1 { #private; /** * Provides a descriptive name for the CacheHandler class. * * The name includes the number of handlers and whether file system caching is used. * If the cache handler is not configured yet, it will return a string indicating so. * * This property is primarily intended for debugging purposes * and its visibility is controlled by the `NEXT_PRIVATE_DEBUG_CACHE` environment variable. * * @returns A string describing the cache handler configuration. * * @example * ```js * // cache-handler.mjs * CacheHandler.onCreation(async () => { * const redisHandler = await createRedisHandler({ * client, * }); * * const localHandler = createLruHandler(); * * return { * handlers: [redisHandler, localHandler], * }; * }); * * // after the Next.js called the onCreation hook * console.log(CacheHandler.name); * // Output: "cache-handler with 2 Handlers" * ``` */ static get name(): string; /** * Registers a hook to be called during the creation of an CacheHandler instance. * This method allows for custom cache configurations to be applied at the time of cache instantiation. * * The provided {@link OnCreationHook} function can perform initialization tasks, modify cache settings, * or integrate additional logic into the cache creation process. This function can either return a {@link CacheHandlerConfig} * object directly for synchronous operations, or a `Promise` that resolves to a {@link CacheHandlerConfig} for asynchronous operations. * * Usage of this method is typically for advanced scenarios where default caching behavior needs to be altered * or extended based on specific application requirements or environmental conditions. * * @param onCreationHook - The {@link OnCreationHook} function to be called during cache creation. * */ static onCreation(onCreationHook: OnCreationHook): void; /** * Creates a new CacheHandler instance. Constructor is intended for internal use only. */ constructor(context: FileSystemCacheContext); get(cacheKey: CacheHandlerParametersGet[0], ctx?: GetIncrementalFetchCacheContext | (GetIncrementalResponseCacheContext & { softTags?: null | []; }) | { softTags: []; }): Promise<CacheHandlerValue | null>; set(cacheKey: CacheHandlerParametersSet[0], incrementalCacheValue: CacheHandlerParametersSet[1], ctx: CacheHandlerParametersSet[2] & { internal_lastModified?: number; tags?: string[]; revalidate?: Revalidate; }): Promise<void>; revalidateTag(tag: CacheHandlerParametersRevalidateTag[0]): Promise<void>; resetRequestCache(): void; } export { CacheHandler };