/** * A bounded LRU cache mapping formula **source text → compiled AST**. * * Parsing is the most repeated non-trivial cost in a spreadsheet: filling a * formula down 10,000 rows produces 10,000 structurally-identical sources that * differ only in their (already-offset) references — and even distinct formulas * are re-compiled every time a column is re-typed or a sheet reloads. Caching the * AST keyed by exact source string removes that cost on the hot path. * * The cache is **capacity-bounded** (LRU eviction) so it can never grow without * limit on a sheet with hundreds of thousands of unique formulas. ASTs are * immutable and never mutated by the evaluator or transposer, so sharing one * instance across cache hits is safe. * * @packageDocumentation */ import type { AstNode } from '../parser/ast.types'; import { type CompileResult } from '../compile'; import type { ResolvedFormulaConfig } from '../config/formula-config'; /** Default maximum number of distinct sources retained. */ export declare const DEFAULT_EXPRESSION_CACHE_CAPACITY = 2048; /** * An LRU cache of compiled formulas. `Map` preserves insertion order, which is * exploited for O(1) LRU: on access the entry is deleted and re-inserted (moved * to the most-recent end); eviction removes the oldest (first) key. */ export declare class ExpressionCache { private readonly capacity; private readonly entries; private hits; private misses; /** * @param capacity - Maximum distinct sources to retain (LRU-evicted beyond it). * Must be at least 1. */ constructor(capacity?: number); /** * Compiles `source`, returning a cached result when the exact source has been * seen before. The `argumentSeparator`/`decimalSeparator` of `config` are part * of the cache key, so a locale change never returns a stale parse. * * @param source - The raw formula source (including `=`). * @param config - Resolved engine configuration (separators). * @returns The compiled {@link CompileResult} (AST or positioned error). */ compile(source: string, config: ResolvedFormulaConfig): CompileResult; /** * Convenience accessor returning just the AST (or `null` on a parse error). * * @param source - The raw formula source. * @param config - Resolved engine configuration. */ compileAst(source: string, config: ResolvedFormulaConfig): AstNode | null; /** Empties the cache and resets its hit/miss counters. */ clear(): void; /** @returns The number of cached sources. */ get size(): number; /** * @returns Cache statistics for diagnostics: hits, misses and hit rate in * `[0, 1]` (0 when there have been no lookups). */ stats(): { hits: number; misses: number; hitRate: number; }; } //# sourceMappingURL=expression-cache.d.ts.map