import { EventEmitter } from 'node:events'; /** * Distributed Cache Invalidation System * * Handles cache invalidation across multiple backend instances using: * 1. Redis Pub/Sub for real-time invalidation * 2. Versioning for graceful degradation * 3. Event-driven architecture for decoupling */ export interface CacheInvalidationMessage { type: 'INVALIDATE_TENANT' | 'INVALIDATE_SERVICE' | 'INVALIDATE_ALL'; tenantId?: string; serviceType?: string; reason?: string; timestamp: number; instanceId: string; } export interface DistributedCacheOptions { redisUrl?: string; channelPrefix?: string; instanceId?: string; enableFallback?: boolean; } export declare class DistributedCacheInvalidator extends EventEmitter { private readonly redis; private readonly subscriber; private readonly channelPrefix; private readonly instanceId; private readonly enableFallback; private heartbeatInterval?; private readonly INVALIDATION_CHANNEL; private readonly HEARTBEAT_CHANNEL; private readonly HEARTBEAT_INTERVAL; constructor(options?: DistributedCacheOptions); /** * Generate unique instance ID for this backend instance */ private generateInstanceId; /** * Setup Redis pub/sub subscriptions */ private setupSubscriptions; /** * Setup heartbeat to monitor Redis connectivity */ private setupHeartbeat; /** * Send heartbeat to other instances */ private sendHeartbeat; /** * Handle incoming invalidation messages */ private handleInvalidationMessage; /** * Handle heartbeat messages (for monitoring) */ private handleHeartbeatMessage; /** * Invalidate all cached data for a specific tenant across all instances */ invalidateTenant(tenantId: string, reason?: string): Promise; /** * Invalidate all cached data for a specific service type across all instances */ invalidateService(serviceType: string, reason?: string): Promise; /** * Invalidate all cached data across all instances */ invalidateAll(reason?: string): Promise; /** * Publish invalidation message to Redis */ private publishInvalidation; /** * Get list of active instances (based on recent heartbeats) */ getActiveInstances(_maxAge?: number): Promise; /** * Cleanup Redis connections */ shutdown(): Promise; } export declare function getDistributedCacheInvalidator(options?: DistributedCacheOptions): DistributedCacheInvalidator;