import type { CacheHandler, CacheHandlerContext, CacheHandlerGetMeta, CacheHandlerGetResult, CacheHandlerOptions, CacheHandlerValue, CacheValue } from "../types.js"; export interface CompositeHandlerOptions extends CacheHandlerOptions { /** * Array of cache handlers to use (ordered by priority) * First handler is checked first for reads */ handlers: CacheHandler[]; /** * Strategy function to determine which handler to use for set operations * Returns the index of the handler to use * * @default - Write to all handlers */ setStrategy?: (data: CacheHandlerValue) => number; } /** * Composite cache handler that orchestrates multiple cache handlers * Enables multi-tier caching strategies (e.g., memory -> Redis) * * Features: * - First-match read strategy (fast fallback) * - Configurable write strategy * - Fault tolerance with Promise.allSettled() * - Parallel revalidation across all handlers * * @example * ```typescript * // Memory + Redis two-tier cache * const handler = createCompositeHandler({ * handlers: [memoryHandler, redisHandler], * // Only cache small items in memory, everything in Redis * setStrategy: (data) => { * const size = JSON.stringify(data).length; * return size < 10000 ? 0 : 1; // 0 = memory, 1 = redis * } * }); * ``` */ export declare class CompositeHandler implements CacheHandler { readonly name = "composite"; private readonly handlers; private readonly setStrategy?; constructor(options: CompositeHandlerOptions); get(key: string, meta?: CacheHandlerGetMeta): Promise; set(key: string, value: CacheValue, context?: CacheHandlerContext): Promise; revalidateTag(tag: string, profile?: string | { expire?: number; }): Promise; delete(key: string): Promise; } /** * Create a composite cache handler instance * * @example * ```typescript * // Route based on tags * const handler = createCompositeHandler({ * handlers: [memoryHandler, redisHandler], * setStrategy: (data) => { * // Use memory for items tagged with "memory-cache" * if (data.tags.includes("memory-cache")) { * return 0; // memory handler * } * return 1; // redis handler * } * }); * ``` */ export declare function createCompositeHandler(options: CompositeHandlerOptions): CompositeHandler; //# sourceMappingURL=composite.d.ts.map