UNPKG

@noanswer/context-compose

Version:

Orchestrate complex AI interactions with Context Compose. A powerful CLI and server for building, validating, and managing context for large language models using the Model Context Protocol (MCP).

105 lines (104 loc) 2.77 kB
/** * Cache configuration */ interface CacheConfig { maxSize: number; defaultTtl: number; } /** * High-performance in-memory cache with TTL and file change detection */ export declare class MemoryCache<T = unknown> { private cache; private accessOrder; private accessCounter; private config; constructor(config?: Partial<CacheConfig>); /** * Get cached value with file change detection */ get(key: string, filePath?: string): Promise<T | undefined>; /** * Set cached value */ set(key: string, value: T, filePath?: string, ttl?: number): Promise<void>; /** * Check if key exists in cache */ has(key: string): boolean; /** * Delete cached value */ delete(key: string): boolean; /** * Clear all cached values */ clear(): void; /** * Get cache statistics */ getStats(): { size: number; maxSize: number; hitRate: number; memoryUsage: number; }; /** * Get file hash for change detection */ private getFileHash; /** * Evict least recently used item */ private evictLRU; /** * Estimate memory usage (rough calculation) */ private estimateMemoryUsage; } /** * Global cache instances */ export declare const yamlCache: MemoryCache<unknown>; export declare const fileCache: MemoryCache<string>; /** * Memoization decorator for functions */ export declare function memoize<TArgs extends readonly unknown[], TReturn>(fn: (...args: TArgs) => TReturn, keyGenerator?: (...args: TArgs) => string): (...args: TArgs) => TReturn; /** * Async memoization decorator */ export declare function memoizeAsync<TArgs extends readonly unknown[], TReturn>(fn: (...args: TArgs) => Promise<TReturn>, keyGenerator?: (...args: TArgs) => string, ttl?: number): (...args: TArgs) => Promise<TReturn>; /** * Start timing an operation */ export declare function startTimer(operation: string): void; /** * End timing an operation and record metrics */ export declare function endTimer(operation: string): number; /** * Get performance metrics for an operation */ export declare function getMetrics(operation: string): { count: number; totalTime: number; avgTime: number; } | undefined; /** * Get all performance metrics */ export declare function getAllMetrics(): Record<string, { count: number; totalTime: number; avgTime: number; }>; /** * Clear all metrics */ export declare function clearMetrics(): void; /** * Decorator for timing function execution */ export declare function timeFunction<TArgs extends readonly unknown[], TReturn>(fn: (...args: TArgs) => TReturn, operationName?: string): (...args: TArgs) => TReturn; export {};