import type { Tool } from '../../../shared/models/tool.model.js'; /** * Search cache service that provides time-based caching for search results. * * This service implements a simple TTL (Time-To-Live) cache mechanism for storing * and retrieving search results. It automatically invalidates cached data after * a specified time period (30 seconds by default) to ensure freshness while * providing performance benefits for repeated searches within the TTL window. * * The cache stores an array of Tool objects and maintains a timestamp of the last * update to determine cache validity. This is particularly useful in scenarios * where search operations might be expensive or frequently repeated, such as * in autocomplete or real-time search interfaces. * * @example * ```typescript * const cache = new SearchCacheService(); * * // Set cache with search results * cache.set(searchResults); * * // Retrieve cached results (returns null if expired) * const results = cache.get(); * * // Manually invalidate cache * cache.invalidate(); * ``` */ export declare class SearchCacheService { private cache; private lastUpdate; private readonly CACHE_TTL; /** * Checks if the current cache is valid based on the TTL (Time-To-Live). * * A cache is considered valid if it exists and has not exceeded the * configured TTL since the last update. The default TTL is 30 seconds. * * @returns {boolean} True if the cache exists and is within the TTL window, * false otherwise (either no cache or expired). * * @example * ```typescript * if (cache.isValid()) { * // Use cached results * const results = cache.get(); * } * ``` */ isValid(): boolean; /** * Retrieves the cached search results if they are still valid. * * This method first checks if the cache is valid using the TTL mechanism. * If the cache is invalid or expired, it automatically clears the cache * and returns null. Otherwise, it returns the cached Tool array. * * @returns {Tool[] | null} The cached array of Tool objects if valid, * null if the cache is invalid, expired, or empty. * * @example * ```typescript * const cachedResults = cache.get(); * if (cachedResults) { * // Use cached results * return cachedResults; * } else { * // Perform fresh search * const freshResults = performSearch(); * cache.set(freshResults); * return freshResults; * } * ``` */ get(): Tool[] | null; /** * Stores search results in the cache with the current timestamp. * * This method sets the provided Tool array as the cached value and * records the current timestamp as the last update time. The cache * will remain valid until it exceeds the TTL (30 seconds by default). * * @param {Tool[]} tools - The array of Tool objects to cache. * Must be a valid array of Tool instances. * * @example * ```typescript * const searchResults = await searchTools('pattern'); * cache.set(searchResults); * ``` */ set(tools: Tool[]): void; /** * Immediately invalidates and clears the current cache. * * This method forces the cache to be cleared by setting the cache to null * and resetting the last update timestamp to zero. After calling this method, * subsequent calls to `get()` will return null until new data is set. * * This is useful when external events indicate that cached data may be stale, * such as when servers are added, removed, or updated. * * @example * ```typescript * // Invalidate cache when server configuration changes * hubManager.on('serverUpdated', () => { * searchCache.invalidate(); * }); * ``` */ invalidate(): void; } //# sourceMappingURL=search-cache.d.ts.map