import { QueryRunner } from 'typeorm'; import { QueryResultCache } from 'typeorm/cache/QueryResultCache'; import { QueryResultCacheOptions } from 'typeorm/cache/QueryResultCacheOptions'; import { Logger } from '../types/logger'; export type CacheKind = 'lru' | 'redis' | 'unknown' | (string & Record); export interface InstrumentedQueryResultCacheOptions { /** * Tag for the underlying backend. Surfaces as the `kind` attribute on every * emitted metric so dashboards can split LRU vs Redis cost/hit behavior. */ kind: CacheKind; /** * Optional logger. When provided, a summary line is logged via `flushSummary()` * and sampled per-op trace logs are emitted if `traceSampleRate > 0`. */ logger?: Logger; /** * Fraction in [0, 1] of get/store ops to log at trace level with the full * identifier. Useful for tracking down hot keys; default 0 (off). */ traceSampleRate?: number; /** * Cap on how many distinct key prefixes are tracked in the per-instance * miss-count map. Prevents unbounded memory growth on services with * unexpected key shapes. Default 256. */ maxTrackedPrefixes?: number; } interface InstrumentationStats { hit: number; miss: number; expired: number; store: number; remove: number; error: number; getLatencyMsSum: number; getLatencyMsMax: number; storeLatencyMsSum: number; storeLatencyMsMax: number; payloadBytesSum: number; payloadBytesMax: number; missesByPrefix: Map; } /** * Decorates any QueryResultCache (LRU, Redis-backed, or otherwise) with * OTel metrics + a lightweight in-process counter that can be dumped as a * single log line per Lambda invocation. * * Hit-rate, lookup latency, payload size, and a low-cardinality miss-by-prefix * breakdown all become visible without per-callsite changes. Same wrapper for * every backend, so cross-service comparisons (Redis hit% on alerts-2.0 vs * forwarder, LRU thrash on api-auth) come for free. */ export declare class InstrumentedQueryResultCache implements QueryResultCache { private readonly inner; private readonly kind; private readonly logger?; private readonly traceSampleRate; private readonly maxTrackedPrefixes; private stats; constructor(inner: QueryResultCache, options: InstrumentedQueryResultCacheOptions); connect(): Promise; disconnect(): Promise; synchronize(queryRunner?: QueryRunner): Promise; getFromCache(options: QueryResultCacheOptions, queryRunner?: QueryRunner): Promise; storeInCache(options: QueryResultCacheOptions, savedCache?: QueryResultCacheOptions, queryRunner?: QueryRunner): Promise; isExpired(saved: QueryResultCacheOptions): boolean; remove(identifiers: string[], queryRunner?: QueryRunner): Promise; clear(): Promise; /** * Emit one log line summarizing every op since the last call, then reset. * Intended for per-Lambda-invocation middleware hooks; safe to call * periodically from long-running processes. */ flushSummary(): void; /** Test-only / introspection accessor. Do not rely on shape across versions. */ snapshotStats(): Readonly; private trackMissPrefix; private maybeTraceLog; } export {};