@rb2bv/cache-handler
Version:
Next.js self-hosting simplified.
64 lines (59 loc) • 1.78 kB
text/typescript
import { Handler } from '../cache-handler.cjs';
import '../next-common-D8C6ukdH.cjs';
import 'next/dist/server/lib/incremental-cache';
import 'next/dist/server/lib/incremental-cache/file-system-cache';
import 'next/dist/server/response-cache/types';
/**
* Configuration options for the LRU cache.
*
* @since 1.0.0
*/
type LruCacheOptions = {
/**
* Optional. Maximum number of items the cache can hold.
*
* @default 1000
*
* @since 1.0.0
*/
maxItemsNumber?: number;
/**
* Optional. Maximum size in bytes for each item in the cache.
*
* @default 104857600 // 100 Mb
*
* @since 1.0.0
*/
maxItemSizeBytes?: number;
};
/**
* @deprecated Use {@link LruCacheOptions} instead.
*/
type LruCacheHandlerOptions = LruCacheOptions;
/**
* Creates an LRU (Least Recently Used) cache Handler.
*
* This function initializes an LRU cache handler for managing cache operations.
* It allows setting a maximum number of items and maximum item size in bytes.
* The handler includes methods to get and set cache values.
* Revalidation is handled by the `CacheHandler` class.
*
* @param options - The configuration options for the LRU cache handler. See {@link LruCacheOptions}.
*
* @returns An object representing the cache, with methods for cache operations.
*
* @example
* ```js
* const lruHandler = createLruHandler({
* maxItemsNumber: 10000, // 10000 items
* maxItemSizeBytes: 1024 * 1024 * 500, // 500 MB
* });
* ```
*
* @remarks
* - Use this Handler as a fallback for any remote store Handler.
*
* @since 1.0.0
*/
declare function createHandler({ ...lruOptions }?: LruCacheOptions): Handler;
export { type LruCacheHandlerOptions, type LruCacheOptions, createHandler as default };