export interface InMemoryCacheOptions { /** When false the cache stores nothing and every lookup misses. Defaults to true. */ enabled?: boolean; /** Minimum entry lifetime in minutes. Defaults to 5. */ minTTL?: number; /** Maximum entry lifetime in minutes. Defaults to 15. */ maxTTL?: number; /** Housekeeping cleanup cadence and search-query retention, in seconds. Defaults to 86400 (24 hours). */ cacheClearUp?: number; } /** * Caches data in memory with smart TTL management: * - Random TTL per entry (5-15 minutes) to prevent cache stampede * - Selective cache invalidation by collection/document * - Auto-cleanup of expired entries */ export declare class InMemoryCache { private readonly enabled; private readonly minTTL; private readonly maxTTL; private readonly cacheClearUp; private cacheObject; private tempSearchQuery; private documentIndex; /** * @param TTL - InMemoryCacheOptions, or a legacy numeric/string value treated as `cacheClearUp`. */ constructor(TTL?: string | number | InMemoryCacheOptions); /** * Generates a random TTL between minTTL and maxTTL * This prevents cache stampede (thundering herd problem) * * @returns Random TTL in milliseconds * @private */ private generateRandomTTL; /** * Each cache entry gets its own random TTL (5-15 minutes) to prevent cache stampede * (synchronized mass-expiration), with expiresAt pre-computed for O(1) validation later. * * @param collectionPath - When provided and `value` is an array of documents (each with a * `documentId`), the entry is registered in the reverse document index so a future * invalidateByDocument(s) call can evict exactly this entry instead of the whole collection. * @example * await cache.setCache('user-123', { name: 'John', age: 30 }); */ setCache(key: string, value: unknown, collectionPath?: string): Promise; /** * Removes a single cache entry and cleans up any reverse document-index references to it, * preventing the index from accumulating stale entries as the cache turns over. */ private evictCacheEntry; /** Tracked for analytics/monitoring only - does not gate or block caching. */ setTempSearchQuery(queryString: Record): Promise; /** * Retrieves a value from the cache using the specified key * Validates TTL expiration and auto-deletes expired entries * * @param key - The unique identifier to lookup in the cache * @returns A Promise that resolves to the cached value if found and not expired, false otherwise */ getCache(key: string): Promise; clearAllCache(): Promise; /** * Selective invalidation (only this collection's cache entries, others untouched). * @example * await cache.invalidateByCollection('/db/users'); * // Only /db/users cache cleared, /db/orders cache remains */ invalidateByCollection(collectionPath: string): Promise; /** * Evicts only the cache entries that actually contained this document (via the reverse * document index), leaving cached results for unrelated documents in the same collection * untouched. If the document was never part of any cached result (e.g. it's brand new), * this is a no-op - callers inserting a new document should use invalidateByCollection * instead, since a cached "list"/filter query could now be missing it. * * Note: for updates, a cached filtered query that the document's *old* values didn't match * won't be invalidated even if the new values would now match it. That staleness is bounded * by the existing cache TTL (5-15 min), the same eventual-consistency window already used by * the index cache elsewhere in this engine. */ invalidateByDocument(collectionPath: string, documentId: string): Promise; /** Same targeted strategy as invalidateByDocument, for a batch of documents. */ invalidateByDocuments(collectionPath: string, documentIds: string[]): Promise; /** Returns estimated cache size/memory stats, or false if calculation fails (logged, not thrown). */ getCacheDetails(): Promise<{ cacheSizeInBytes: number; availableMemoryInBytes: number; cacheItemCount: number; tempQueryCount: number; } | false>; /** Periodically evicts expired cache entries and old search-query tracking. */ private autoResetCache; }