import { FlowBlock } from '../../contracts/src/index.js'; /** * Cache statistics with LRU eviction tracking */ export type MeasureCacheStats = { hits: number; misses: number; sets: number; invalidations: number; clears: number; /** * Number of entries evicted due to LRU policy */ evictions: number; /** * Current cache size (number of entries) */ size: number; /** * Estimated memory usage (bytes) */ memorySizeEstimate: number; }; /** * LRU-enhanced MeasureCache * * Key improvements: * 1. Bounded size: max 10,000 entries * 2. LRU eviction: Evicts least recently used when full * 3. O(1) access and eviction using Map insertion order * 4. Memory usage estimation * 5. Eviction statistics * * Performance characteristics: * - get(): O(1) - Map lookup + delete + re-insert for LRU tracking * - set(): O(1) - eviction (delete first key) + insert * - invalidate(): O(n) - where n = number of keys matching blockId prefix * - Memory: Bounded at 10K entries ~= 50-100MB */ export declare class MeasureCache { private cache; private stats; /** * Retrieve a cached measure for the given block and dimensions. * Returns undefined if the block is null/undefined, lacks an ID, or if no cached value exists. * * @param block - The flow block to look up (may be null/undefined) * @param width - The width dimension for cache key * @param height - The height dimension for cache key * @returns The cached value or undefined */ get(block: FlowBlock | null | undefined, width: number, height: number): T | undefined; /** * Store a measure in the cache for the given block and dimensions. * Silently returns if the block is null/undefined or lacks an ID. * * @param block - The flow block to cache (may be null/undefined) * @param width - The width dimension for cache key * @param height - The height dimension for cache key * @param value - The value to cache */ set(block: FlowBlock | null | undefined, width: number, height: number, value: T): void; /** * Invalidates cached measurements for specific block IDs. * Removes all cache entries whose keys start with any of the provided block IDs. * * @param blockIds - Array of block IDs to invalidate from the cache * * @example * ```typescript * cache.invalidate(['block-123', 'block-456']); * ``` */ invalidate(blockIds: string[]): void; /** * Clears all cached measurements and resets statistics. * Use when performing a full document re-layout. */ clear(): void; /** * Resets cache statistics (hits, misses, sets) to zero. * Does not clear cached values. */ resetStats(): void; /** * Returns current cache performance statistics. * Useful for monitoring cache effectiveness. * * @returns Object containing hits, misses, sets, and hit rate */ getStats(): MeasureCacheStats; /** * Get current cache size (number of entries) */ getSize(): number; /** * Get maximum cache size */ getMaxSize(): number; /** * Check if cache is near capacity */ isNearCapacity(threshold?: number): boolean; /** * Update size statistics */ private updateSizeStats; /** * Composes a cache key from block properties and dimensions. * Validates and clamps dimensions to prevent memory exhaustion. * * @param block - The flow block to create a key for * @param width - Width dimension (will be clamped to [0, MAX_DIMENSION]) * @param height - Height dimension (will be clamped to [0, MAX_DIMENSION]) * @returns Cache key string */ private composeKey; } //# sourceMappingURL=cache.d.ts.map