import { Redis as IORedis } from 'ioredis'; /** * Base cache options */ export interface BaseCacheOptions { /** * Default Time-To-Live (TTL) in milliseconds */ ttl?: number; /** * Key prefix to use for all cache keys */ keyPrefix?: string; /** * Whether to serialize values (default: true) */ serialize?: boolean; /** * Whether to log cache operations (default: false) */ enableLogging?: boolean; /** * Log level for cache operations */ logLevel?: 'debug' | 'info' | 'warn' | 'error'; } /** * Memory cache options */ export interface MemoryCacheOptions extends BaseCacheOptions { /** * Maximum number of items in the cache */ maxItems?: number; /** * Maximum size of the cache in bytes */ maxSize?: number; /** * Eviction strategy when cache is full */ evictionStrategy?: 'lru' | 'lfu' | 'fifo'; /** * Check interval for expired items in milliseconds */ checkExpirationInterval?: number; /** * Whether to delete expired items on get (default: true) */ deleteExpiredOnGet?: boolean; } /** * Redis cache options */ export interface RedisCacheOptions extends BaseCacheOptions { /** * Redis connection options */ connection?: { host?: string; port?: number; username?: string; password?: string; db?: number; tls?: boolean; url?: string; }; /** * Existing Redis client instance */ client?: IORedis; /** * Whether to handle connection errors automatically (default: true) */ handleErrors?: boolean; /** * Maximum number of reconnect attempts */ maxReconnectAttempts?: number; /** * Reconnect strategy */ reconnectStrategy?: 'linear' | 'exponential'; } /** * Tiered cache options */ export interface TieredCacheOptions extends BaseCacheOptions { /** * Array of cache providers in order of access (L1, L2, ...) */ providers: { /** * Provider instance */ provider: any; /** * Provider options */ options?: { /** * Whether to write to this tier on cache hits from lower tiers */ writeOnHitFromLowerTier?: boolean; /** * TTL for this tier (overrides the global TTL) */ ttl?: number; }; }[]; /** * Cache write strategy */ writeStrategy?: 'write-through' | 'write-behind' | 'write-around'; /** * Whether to propagate deletes to all tiers */ propagateDeletes?: boolean; /** * Whether to propagate updates to all tiers */ propagateUpdates?: boolean; /** * Maximum time in ms to wait for lower tier responses */ tierTimeout?: number; } /** * Cache invalidation options */ export interface InvalidationOptions { /** * Invalidation method */ method: 'tag' | 'pattern' | 'version'; /** * Tags for tag-based invalidation */ tags?: string[]; /** * Pattern for pattern-based invalidation */ pattern?: string; /** * Version for version-based invalidation */ version?: string | number; /** * Whether to cascade invalidation to related keys */ cascade?: boolean; /** * Maximum number of keys to invalidate in one operation */ maxKeys?: number; } /** * Combined cache options type */ export type CacheOptions = BaseCacheOptions & { memory?: MemoryCacheOptions; redis?: RedisCacheOptions; tiered?: TieredCacheOptions; invalidation?: InvalidationOptions; };