@rhofkens/mcp-quotes-server-claude-code
Version:
Model Context Protocol (MCP) server for managing and serving quotes
102 lines • 2.34 kB
TypeScript
/**
* Cache Layer for Quote Responses
*
* Provides in-memory caching with TTL support for API responses
* to enable fallback mechanisms and reduce API calls
*/
import type { IQuote } from '../types/quotes.js';
/**
* Cache statistics for monitoring
*/
export interface ICacheStats {
hits: number;
misses: number;
evictions: number;
size: number;
}
/**
* Cache configuration options
*/
export interface ICacheConfig {
maxSize?: number;
defaultTTL?: number;
enableStats?: boolean;
}
/**
* Generic in-memory cache with TTL and LRU eviction
*/
export declare class Cache<T = unknown> {
private cache;
private readonly maxSize;
private readonly defaultTTL;
private stats;
private readonly enableStats;
constructor(config?: ICacheConfig);
/**
* Get an item from cache
*/
get(key: string): T | null;
/**
* Set an item in cache with optional TTL
*/
set(key: string, data: T, ttl?: number): void;
/**
* Check if a key exists and is not expired
*/
has(key: string): boolean;
/**
* Delete an item from cache
*/
delete(key: string): boolean;
/**
* Clear all cache entries
*/
clear(): void;
/**
* Get cache statistics
*/
getStats(): Readonly<ICacheStats>;
/**
* Reset cache statistics
*/
resetStats(): void;
/**
* Get all keys in cache
*/
keys(): string[];
/**
* Evict least recently used entry
*/
private evictLRU;
/**
* Clean up expired entries
*/
cleanup(): void;
}
/**
* Specialized cache for quote responses
*/
export declare class QuoteCache extends Cache<IQuote[]> {
constructor();
/**
* Generate cache key for quote requests
*/
static generateKey(person: string, topic?: string, numberOfQuotes?: number): string;
/**
* Get quotes from cache with fallback to stale data
*/
getWithFallback(key: string): {
data: IQuote[] | null;
stale: boolean;
};
/**
* Warm up cache with common searches
*/
warmup(commonSearches: Array<{
person: string;
topic?: string;
}>): Promise<void>;
}
export declare const quoteCache: QuoteCache;
export declare const defaultCache: Cache<unknown>;
//# sourceMappingURL=cache.d.ts.map