@fortedigital/nextjs-cache-handler
Version:
Next.js cache handlers
43 lines (40 loc) • 1.67 kB
text/typescript
import { LRUCache } from 'lru-cache';
import { Handler } from './cache-handler.types.cjs';
import { LruCacheOptions } from './local-lru.types.cjs';
import 'next/dist/server/lib/incremental-cache';
import 'next/dist/server/lib/incremental-cache/file-system-cache';
/**
* Creates a configured LRUCache.
*
* @param calculateSizeCallback - A callback function to calculate the size of cache items.
*
* @param options - Optional configuration options for the cache.
*
* @returns A new instance of LRUCache.
*/
declare function createConfiguredCache<CacheValueType extends object | string>(calculateSizeCallback: (value: CacheValueType) => number, { maxItemsNumber, maxItemSizeBytes, }?: LruCacheOptions): LRUCache<string, CacheValueType>;
/**
* 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.
*/
declare function createHandler({ ...lruOptions }?: LruCacheOptions): Handler;
export { createConfiguredCache, createHandler as default };