import type { CacheDependency } from './cache-dependency.interface'; /** * Cache layer enum - defines the three-tier cache architecture */ export declare enum CacheLayer { /** L1: Request-level cache (nestjs-cls) - fastest, scoped to request */ CLS = "cls", /** L2: Process-level cache (native Map) - fast, scoped to process */ MEMORY = "memory", /** L3: Distributed cache (Redis) - persistent, shared across processes */ REDIS = "redis" } /** * Cache configuration options */ export interface CacheOptions { /** * Time to live in milliseconds * @example 300_000 // 5 minutes */ ttl?: number; /** * Cache layers to use * @default [CacheLayer.MEMORY, CacheLayer.REDIS] */ layers?: CacheLayer[]; /** * Key prefix for namespacing * @example 'user:' will result in keys like 'user:123' */ prefix?: string; /** * Condition function to determine if value should be cached * @param args - Method arguments * @returns true to cache, false to skip */ condition?: (...args: any[]) => boolean | Promise; /** * Unless condition - skip caching when this condition is true * Can be a function (safe) or a string expression (use with caution) * @param result - Method return value * @param args - Method arguments * @returns true to skip caching, false to cache normally */ unless?: ((result: any, args: any[]) => boolean) | string; /** * Cache dependencies - cache will be invalidated when dependencies change * Similar to Yii2 cache dependency system */ dependencies?: CacheDependency[]; /** * Whether to backfill upper cache layers when value is found in lower layer * @default true */ backfill?: boolean; /** * Namespace for grouping related cache keys */ namespace?: string; } /** * Options for cache decorator key generation */ export interface CacheKeyOptions { /** * Static key or key generator function * * The key function can return: * - string (directly used as key) * - number or bigint (converted to string) * - boolean (converted to "true" or "false") * - object (stringified using JSON.stringify) * * Returning null, undefined, empty string, or empty object will throw KeyGenerationError. */ key?: string | ((...args: any[]) => string | number | boolean | object); /** * Key prefix */ prefix?: string; /** * Whether to include all method arguments in key generation * @default false */ includeAllArgs?: boolean; } /** * Options for @Cacheable decorator */ export interface CacheableOptions extends CacheOptions, CacheKeyOptions { } /** * Options for @CacheEvict decorator */ export interface CacheEvictOptions { /** * Keys to evict (can be static strings or generator functions) */ keys?: Array string)>; /** * Patterns to match for eviction (supports wildcards) * @example ['user:*', 'posts:list:*'] */ patterns?: string[]; /** * Tags to invalidate */ tags?: string[]; /** * Cache layers to evict from */ layers?: CacheLayer[]; /** * Condition to determine if eviction should occur * @param args - Method arguments * @param result - Method return value */ condition?: (...args: any[]) => boolean | Promise; /** * Whether to evict before or after method execution * @default 'after' */ timing?: 'before' | 'after'; } /** * Options for @CachePut decorator */ export interface CachePutOptions extends CacheOptions, CacheKeyOptions { }