/** * 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 ttl; private cacheObject; private tempSearchQuery; private readonly autoResetCacheInterval; private documentIndex; /** @param TTL - Time to live in seconds for cache entries. Defaults to 86400 seconds (24 hours) */ constructor(TTL?: string | number); /** * Generates a random TTL between 5-15 minutes * 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: any, 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: any): 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; /** Periodically evicts expired cache entries and old search-query tracking. */ private autoResetCache; } declare const _default: InMemoryCache; export default _default;