UNPKG

amazon-seller-mcp

Version:

Model Context Protocol (MCP) client for Amazon Selling Partner API

184 lines (183 loc) 4.29 kB
/** * Cache management system for Amazon Seller MCP Client * * This file implements advanced caching strategies for improved performance: * - Tiered caching (memory and persistent) * - TTL-based expiration * - LRU eviction policy * - Cache statistics and monitoring */ /** * Cache statistics */ interface CacheStats { /** * Total number of cache hits */ hits: number; /** * Total number of cache misses */ misses: number; /** * Total number of cache entries */ size: number; /** * Hit ratio (hits / (hits + misses)) */ hitRatio: number; } /** * Cache configuration options */ export interface CacheConfig { /** * Default TTL in seconds * @default 60 */ defaultTtl?: number; /** * Check period in seconds * @default 120 */ checkPeriod?: number; /** * Maximum number of entries * @default 1000 */ maxEntries?: number; /** * Whether to use persistent cache * @default false */ persistent?: boolean; /** * Directory for persistent cache * @default '~/.amazon-seller-mcp/cache' */ persistentDir?: string; /** * Whether to collect statistics * @default true */ collectStats?: boolean; } /** * Advanced cache manager for improved performance */ export declare class CacheManager { /** * Memory cache */ private memoryCache; /** * Cache configuration */ private config; /** * Cache statistics */ private stats; /** * Whether the persistent cache directory has been initialized */ private persistentCacheInitialized; /** * Create a new cache manager * * @param config Cache configuration */ constructor(config?: CacheConfig); /** * Initialize persistent cache */ private initPersistentCache; /** * Get a value from the cache * * @param key Cache key * @returns Cached value or undefined if not found */ get<T>(key: string): Promise<T | undefined>; /** * Set a value in the cache * * @param key Cache key * @param value Value to cache * @param ttl Time to live in seconds (optional, defaults to config.defaultTtl) */ set<T>(key: string, value: T, ttl?: number): Promise<void>; /** * Delete a value from the cache * * @param key Cache key * @returns Whether the key was deleted */ del(key: string): Promise<boolean>; /** * Clear the entire cache */ clear(): Promise<void>; /** * Get cache statistics * * @returns Cache statistics */ getStats(): CacheStats; /** * Get a value from the persistent cache * * @param key Cache key * @returns Cached value or undefined if not found */ private getFromPersistentCache; /** * Set a value in the persistent cache * * @param key Cache key * @param value Value to cache * @param ttl Time to live in seconds (optional, defaults to config.defaultTtl) */ private setInPersistentCache; /** * Delete a value from the persistent cache * * @param key Cache key */ private deleteFromPersistentCache; /** * Get the file path for a persistent cache key * * @param key Cache key * @returns File path */ private getPersistentCachePath; /** * Execute a function with caching * * @param key Cache key * @param fn Function to execute if cache miss * @param ttl Time to live in seconds (optional) * @returns Function result */ withCache<T>(key: string, fn: () => Promise<T>, ttl?: number): Promise<T>; } /** * Configure the default cache manager * * @param config Cache configuration */ export declare function configureCacheManager(config: CacheConfig): void; /** * Get the default cache manager instance * * @returns Default cache manager instance */ export declare function getCacheManager(): CacheManager; declare const _default: { CacheManager: typeof CacheManager; configureCacheManager: typeof configureCacheManager; getCacheManager: typeof getCacheManager; }; export default _default;