import { EventEmitter } from 'events'; import type { Express } from 'express'; import type { GrafservBase } from 'grafserv'; import type { Server as HttpServer } from 'http'; import { LRUCache } from 'lru-cache'; import type { PostGraphileInstance } from 'postgraphile'; export declare const ONE_HOUR_MS: number; export declare const FIVE_MINUTES_MS: number; export type EvictionReason = 'lru' | 'ttl' | 'manual'; export interface CacheEvictionEvent { key: string; reason: EvictionReason; entry: GraphileCacheEntry; } export declare class CacheEventEmitter extends EventEmitter { emitEviction(event: CacheEvictionEvent): void; onEviction(handler: (event: CacheEvictionEvent) => void): void; } export declare const cacheEvents: CacheEventEmitter; export interface CacheConfig { max: number; ttl: number; } /** * Get cache configuration from environment variables * * Supports: * - GRAPHILE_CACHE_MAX: Maximum number of entries (default: 50) * - GRAPHILE_CACHE_TTL_MS: TTL in milliseconds * - Production default: ONE_YEAR * - Development default: FIVE_MINUTES_MS * * NOTE: This value should be <= PG_CACHE_MAX (also default: 50) so that * every cached PostGraphile instance has a live pool backing it. */ export declare function getCacheConfig(): CacheConfig; /** * Cache entry for PostGraphile v5 instances * * Each entry contains: * - pgl: The PostGraphile instance (manages schema, plugins, etc.) * - serv: The Grafserv server instance (handles HTTP/WS) * - handler: Express app for routing requests * - httpServer: Node HTTP server (required by grafserv) * - cacheKey: Unique identifier for this entry * - createdAt: Timestamp when this entry was created */ export interface GraphileCacheEntry { pgl: PostGraphileInstance; serv: GrafservBase; handler: Express; httpServer: HttpServer; cacheKey: string; createdAt: number; /** Optional RealtimeManager for cursor-tracked subscription delivery */ realtimeManager?: { stop(): Promise; } | null; } export declare const graphileCache: LRUCache; export interface CacheStats { size: number; max: number; ttl: number; keys: string[]; } /** * Get current cache statistics */ export declare function getCacheStats(): CacheStats; /** * Clear cache entries matching a regex pattern * * @param pattern - RegExp to match against cache keys * @returns Number of entries cleared */ export declare function clearMatchingEntries(pattern: RegExp): number; /** * Close all caches and release resources * * This function: * 1. Disposes all PostGraphile v5 instances (async) * 2. Clears the graphile cache * 3. Closes all pg pools via pgCache * * The function is idempotent - calling it multiple times * returns the same promise. */ export declare const closeAllCaches: (verbose?: boolean) => Promise;