UNPKG

mcp-adr-analysis-server

Version:

MCP server for analyzing Architectural Decision Records and project architecture

144 lines 4.16 kB
/** * Resource-level caching infrastructure for MCP resources * Provides efficient caching with TTL support, cache management, * and conditional request support (ETags, Last-Modified) */ import type { ResourceMetadata } from '../utils/resource-versioning.js'; export interface CacheEntry { data: any; expiry: number; createdAt: number; accessCount: number; lastAccessed: number; etag?: string; lastModified?: string; version?: string; metadata?: ResourceMetadata; } export interface CacheStats { totalEntries: number; validEntries: number; expiredEntries: number; cacheSize: number; hitRate: number; totalHits: number; totalMisses: number; } /** * Resource cache with TTL support and statistics tracking */ export declare class ResourceCache { private cache; private hits; private misses; /** * Get cached resource by key * @param key Cache key * @returns Cached data or null if not found/expired */ get<T>(key: string): Promise<T | null>; /** * Get cached resource with conditional request support * @param key Cache key * @param conditionalHeaders Optional conditional headers * @returns Result with data, metadata, and notModified flag */ getWithConditional<T>(key: string, conditionalHeaders?: { ifNoneMatch?: string; ifModifiedSince?: string; }): Promise<{ data: T | null; notModified: boolean; etag?: string; lastModified?: string; version?: string; metadata?: ResourceMetadata; }>; /** * Set cached resource with TTL * @param key Cache key * @param data Data to cache * @param ttl Time to live in seconds * @param metadata Optional metadata (etag, lastModified, version, resourceMetadata) */ set(key: string, data: any, ttl: number, metadata?: { etag?: string; lastModified?: string; version?: string; resourceMetadata?: ResourceMetadata; }): void; /** * Check if key exists and is valid * @param key Cache key * @returns True if key exists and is not expired */ has(key: string): boolean; /** * Delete cached resource * @param key Cache key * @returns True if key was deleted */ delete(key: string): boolean; /** * Clear cache entries matching pattern * @param pattern Optional pattern to match keys (substring match) */ clear(pattern?: string): void; /** * Clean up expired entries * @returns Number of entries removed */ cleanup(): number; /** * Get cache statistics * @returns Cache statistics object */ getStats(): CacheStats; /** * Get all cache keys * @returns Array of all cache keys */ keys(): string[]; /** * Get cache entries sorted by access count * @param limit Maximum number of entries to return * @returns Top entries by access count */ getTopEntries(limit?: number): Array<{ key: string; accessCount: number; }>; /** * Get least recently used entries * @param limit Maximum number of entries to return * @returns Least recently used entries */ getLRUEntries(limit?: number): Array<{ key: string; lastAccessed: number; }>; /** * Evict least recently used entries to reduce cache size * @param targetSize Target number of entries * @returns Number of entries evicted */ evictLRU(targetSize: number): number; /** * Reset cache statistics */ resetStats(): void; } /** * Singleton resource cache instance */ export declare const resourceCache: ResourceCache; export declare function startAutomaticCleanup(intervalMs?: number): void; export declare function stopAutomaticCleanup(): void; /** * Generate ETag for resource data * @deprecated Use generateStrongETag from conditional-request.ts instead * @param data Resource data * @returns ETag string */ export declare function generateETag(data: any): string; //# sourceMappingURL=resource-cache.d.ts.map