@ever_cheng/memory-task-mcp
Version:
Memory and task management MCP Server
98 lines (97 loc) • 2.55 kB
TypeScript
import Logger from './logger';
import { CacheConfig, CacheStats } from './types';
/**
* Unified Cache Service Interface
*/
export interface ICacheService<K, V> {
get(key: K): V | undefined;
set(key: K, value: V): void;
delete(key: K): boolean;
clear(): void;
has(key: K): boolean;
size(): number;
getStats(): CacheStats;
}
/**
* Cache Service Implementation
*
* Provides a unified caching interface that wraps the LRUCache implementation
* with additional functionality and consistent API across all managers.
*/
export declare class CacheService<K, V> implements ICacheService<K, V> {
private cache;
private logger?;
/**
* Constructor
* @param config Cache configuration
* @param logger Optional logger instance
*/
constructor(config: CacheConfig, logger?: Logger);
/**
* Get cached item
* @param key Cache key
* @returns Cached value or undefined if not found or expired
*/
get(key: K): V | undefined;
/**
* Set cached item
* @param key Cache key
* @param value Value to cache
*/
set(key: K, value: V): void;
/**
* Delete cached item
* @param key Cache key
* @returns true if item was deleted, false if not found
*/
delete(key: K): boolean;
/**
* Clear all cached items
*/
clear(): void;
/**
* Check if key exists in cache
* @param key Cache key
* @returns true if key exists and not expired
*/
has(key: K): boolean;
/**
* Get current cache size
* @returns Number of cached items
*/
size(): number;
/**
* Get cache statistics
* @returns Cache hit/miss statistics
*/
getStats(): CacheStats;
/**
* Get cache configuration info for debugging
*/
getInfo(): {
size: number;
stats: CacheStats;
};
}
/**
* Cache Service Factory
*
* Creates CacheService instances with consistent configuration
*/
export declare class CacheServiceFactory {
private logger?;
constructor(logger?: Logger);
/**
* Create a new cache service instance
* @param config Cache configuration
* @returns New CacheService instance
*/
create<K, V>(config: CacheConfig): CacheService<K, V>;
/**
* Create cache service with default configuration
* @param maxSize Maximum cache size
* @param ttlMs TTL in milliseconds
* @returns New CacheService instance
*/
createDefault<K, V>(maxSize?: number, ttlMs?: number): CacheService<K, V>;
}