/** * Structure of index data stored in index files */ interface IndexData { fieldName: string; indexEntries: { [value: string]: string[]; }; /** * Sorted, de-duplicated numeric values for this field - enables O(log U + M) * range queries ($gt/$gte/$lt/$lte) instead of a full collection scan. * Optional for backward compatibility with indexes written before range * support existed; those are lazily backfilled on first insert/delete. */ sortedValues?: number[]; } /** * In-memory cache for index data * * Features: * - Eagerly loads all indexes on collection initialization * - Keeps indexes in both memory (speed) and disk (persistence) as JSONL * - Cold start recovery: Streams from disk on cache miss * - Thread-safe with simple lock mechanism * - Dual-write: Updates both memory and disk atomically * * @example * ```typescript * const indexCache = IndexCache.getInstance('/path/to/collection'); * await indexCache.loadAllIndexes(); // Eager load (streamed) * const indexData = await indexCache.getIndex('email'); // O(1) memory access * ``` */ export declare class IndexCache { private static instances; private cache; private readonly indexFolderPath; private readonly indexMetaPath; private readonly fileManager; private readonly converter; private lockChains; private cleanupInterval; private static readonly MIN_TTL_MS; private static readonly MAX_TTL_MS; private static readonly CLEANUP_INTERVAL_MS; private constructor(); /** * Returns the shared IndexCache for a collection path, creating it on first use. */ static getInstance(collectionPath: string): IndexCache; /** * Releases the shared IndexCache for a collection path. */ static releaseInstance(collectionPath: string): void; /** * Stops the cleanup timer and clears cached state. */ dispose(): void; /** * Generates a random TTL between 5-15 minutes. */ private generateRandomTTL; /** * Starts periodic cleanup of expired cache entries. */ private startCleanupInterval; /** * Removes all expired entries from cache. */ private cleanupExpiredEntries; /** * Checks if a cached entry is expired. */ private isExpired; /** * Eagerly loads all indexes into memory using streaming reads. * Called during collection initialization for maximum query performance. * * @returns Promise that resolves when all indexes are loaded */ loadAllIndexes(): Promise; /** * Gets index data for a specific field. * Returns from memory if available, loads from disk via streaming if not (cold start recovery). */ getIndex(fieldName: string): Promise; /** * Updates an index in both memory and disk atomically. * Writes in JSONL format. */ updateIndex(fieldName: string, indexData: IndexData): Promise; /** * Invalidates a specific index (removes from memory). */ invalidateIndex(fieldName: string): Promise; /** * Invalidates all indexes (removes all from memory). */ invalidateAll(): Promise; /** * Acquires a per-field mutex. */ private acquireLock; /** * Gets current cache statistics for monitoring. */ getCacheStats(): { indexCount: number; fieldNames: string[]; }; } export {};