/** * ThreadTS Universal - Caching Decorators * * Decorators for caching and memoization of method results. * Supports both legacy (experimentalDecorators) and Stage-3 decorator syntax. * * Uses the shared LRUCache class for consistent caching behavior * and follows the DRY principle (Don't Repeat Yourself). * * @module decorators/caching * @author ThreadTS Universal Team */ /** * Type for augmented methods with cache controls. */ export interface CacheableMethod { /** Clears the method's cache */ clearCache?: () => void; /** Returns cache statistics */ getCacheStats?: () => { size: number; maxSize: number; }; } /** * Type for augmented methods with reset controls. */ export interface LazyMethod { /** Resets the lazy state */ reset?: () => void; /** Checks whether it's already initialized */ isInitialized?: () => boolean; } /** * Decorator for memoization with an optional cache size limit. * * Caches method results based on arguments. If called with the same * arguments, the cached result is returned. Uses LRU (Least Recently Used) * eviction when the maximum size is reached. * * @param maxCacheSize - Maximum number of cached entries (default: 100) * @returns Method Decorator * * @example * ```typescript * class Calculator { * @memoize(50) // Cache up to 50 inputs * async computeExpensive(input: number): Promise { * // Expensive computation... * return result; * } * } * ``` */ export declare function memoize(maxCacheSize?: number): (targetOrMethod: unknown, propertyKeyOrContext?: string | symbol | import('./utils').DecoratorContext, descriptor?: PropertyDescriptor) => import('./utils').DecoratorReturnType; /** * Decorator for caching with TTL (time-to-live) support. * * Similar to memoize, but with automatic expiration of cache entries. * Ideal for data that may change periodically. * * @param ttlMs - Time-to-live in milliseconds (default: 60000 = 1 minute) * @param maxSize - Maximum cache size (default: 100) * @returns Method Decorator * * @example * ```typescript * class DataService { * @cache(30000, 50) // Cache for 30 seconds, max 50 entries * async fetchData(id: string): Promise { * return await api.getData(id); * } * * refreshData(id: string) { * // Manual clear if needed * (this.fetchData as any).clearCache(); * } * } * ``` */ export declare function cache(ttlMs?: number, maxSize?: number): (targetOrMethod: unknown, propertyKeyOrContext?: string | symbol | import('./utils').DecoratorContext, descriptor?: PropertyDescriptor) => import('./utils').DecoratorReturnType; /** * Decorator for lazy initialization. * * The method is executed only once on the first call. * All subsequent calls return the stored result. * Supports concurrent calls during initialization without race conditions. * * @returns Method Decorator * * @example * ```typescript * class ConfigService { * @lazy() * async loadConfig(): Promise { * console.log('Loading config...'); // Printed only once * return await fetchConfig(); * } * * async resetAndReload() { * (this.loadConfig as any).reset(); * return await this.loadConfig(); * } * } * ``` */ export declare function lazy(): (targetOrMethod: unknown, propertyKeyOrContext?: string | symbol | import('./utils').DecoratorContext, descriptor?: PropertyDescriptor) => import('./utils').DecoratorReturnType; //# sourceMappingURL=caching.d.ts.map