import type { CacheDependency } from '../interfaces/cache-dependency.interface'; /** * Time-based cache dependency * * This dependency invalidates cache after a specific duration. * Unlike TTL which is checked on read, this is checked as a dependency. * * Useful for implementing complex time-based invalidation logic. * * @example * ```typescript * // Cache for 5 minutes * @Cacheable({ * key: 'daily:report', * dependencies: [ * new TimeDependency(5 * 60 * 1000) // 5 minutes * ] * }) * async getDailyReport() { } * * // Cache until midnight * @Cacheable({ * key: 'today:stats', * dependencies: [ * new TimeDependency(() => { * const now = new Date(); * const midnight = new Date(now); * midnight.setHours(24, 0, 0, 0); * return midnight.getTime() - now.getTime(); * }) * ] * }) * async getTodayStats() { } * ``` */ export declare class TimeDependency implements CacheDependency { private readonly duration; private createdAt; constructor(duration: number | (() => number)); getKey(): string; getData(): Promise<{ createdAt: number; duration: number; }>; isChanged(oldData: { createdAt: number; duration: number; }): Promise; reset(): Promise; /** * Get remaining time in milliseconds */ getRemainingTime(): number; /** * Check if dependency has expired */ isExpired(): boolean; /** * Resolve duration value (handle dynamic duration) */ private resolveDuration; }