UNPKG

memtask

Version:

Memory and task management MCP Server with Goal-Task-Memory architecture

124 lines 3.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheServiceFactory = exports.CacheService = void 0; /** * Unified Cache Service Implementation * * This module provides a unified caching solution to eliminate code duplication * across MemoryManager, TaskManager, and ContextManager. It's based on the * existing LRUCache implementation from utils.ts with additional features. */ const utils_1 = require("./utils"); /** * Cache Service Implementation * * Provides a unified caching interface that wraps the LRUCache implementation * with additional functionality and consistent API across all managers. */ class CacheService { /** * Constructor * @param config Cache configuration * @param logger Optional logger instance */ constructor(config, logger) { this.cache = new utils_1.LRUCache(config.maxSize, config.ttlMs, logger); this.logger = logger; this.logger?.debug('CacheService created', { maxSize: config.maxSize, ttlMs: config.ttlMs }); } /** * Get cached item * @param key Cache key * @returns Cached value or undefined if not found or expired */ get(key) { return this.cache.get(key); } /** * Set cached item * @param key Cache key * @param value Value to cache */ set(key, value) { this.cache.set(key, value); } /** * Delete cached item * @param key Cache key * @returns true if item was deleted, false if not found */ delete(key) { return this.cache.delete(key); } /** * Clear all cached items */ clear() { this.cache.clear(); this.logger?.debug('Cache cleared'); } /** * Check if key exists in cache * @param key Cache key * @returns true if key exists and not expired */ has(key) { return this.cache.get(key) !== undefined; } /** * Get current cache size * @returns Number of cached items */ size() { return this.cache.size(); } /** * Get cache statistics * @returns Cache hit/miss statistics */ getStats() { return this.cache.getStats(); } /** * Get cache configuration info for debugging */ getInfo() { return { size: this.size(), stats: this.getStats() }; } } exports.CacheService = CacheService; /** * Cache Service Factory * * Creates CacheService instances with consistent configuration */ class CacheServiceFactory { constructor(logger) { this.logger = logger; } /** * Create a new cache service instance * @param config Cache configuration * @returns New CacheService instance */ create(config) { return new CacheService(config, this.logger); } /** * Create cache service with default configuration * @param maxSize Maximum cache size * @param ttlMs TTL in milliseconds * @returns New CacheService instance */ createDefault(maxSize = 100, ttlMs = 3600000) { return this.create({ maxSize, ttlMs }); } } exports.CacheServiceFactory = CacheServiceFactory; //# sourceMappingURL=cache.js.map