Skip to main content
Glama
jedarden

YouTube Transcript DL MCP Server

by jedarden
cache.ts2.51 kB
import NodeCache from 'node-cache'; import { Logger } from './logger.js'; export class Cache { private cache: NodeCache; private enabled: boolean; constructor(ttl: number = 3600, maxSize: number = 1000, enabled: boolean = true) { this.enabled = enabled; this.cache = new NodeCache({ stdTTL: ttl, checkperiod: 120, maxKeys: maxSize, useClones: false }); // Setup cache event listeners this.cache.on('set', (key, value) => { Logger.debug(`Cache SET: ${key}`, { size: this.cache.getStats().keys }); }); this.cache.on('del', (key, value) => { Logger.debug(`Cache DEL: ${key}`, { size: this.cache.getStats().keys }); }); this.cache.on('expired', (key, value) => { Logger.debug(`Cache EXPIRED: ${key}`, { size: this.cache.getStats().keys }); }); } public get<T>(key: string): T | undefined { if (!this.enabled) return undefined; const value = this.cache.get<T>(key); if (value) { Logger.debug(`Cache HIT: ${key}`); } else { Logger.debug(`Cache MISS: ${key}`); } return value; } public set<T>(key: string, value: T, ttl?: number): boolean { if (!this.enabled) return false; const success = this.cache.set(key, value, ttl || 0); Logger.debug(`Cache SET: ${key}`, { success, ttl }); return success; } public del(key: string): number { if (!this.enabled) return 0; const deleted = this.cache.del(key); Logger.debug(`Cache DEL: ${key}`, { deleted }); return deleted; } public flush(): void { if (!this.enabled) return; this.cache.flushAll(); Logger.debug('Cache flushed'); } public getStats(): NodeCache.Stats { return this.cache.getStats(); } public getKeys(): string[] { return this.cache.keys(); } public has(key: string): boolean { if (!this.enabled) return false; return this.cache.has(key); } public getTtl(key: string): number | undefined { if (!this.enabled) return undefined; const ttl = this.cache.getTtl(key); return ttl ? ttl : undefined; } public setTtl(key: string, ttl: number): boolean { if (!this.enabled) return false; return this.cache.ttl(key, ttl); } public enable(): void { this.enabled = true; Logger.info('Cache enabled'); } public disable(): void { this.enabled = false; Logger.info('Cache disabled'); } public isEnabled(): boolean { return this.enabled; } } export default Cache;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jedarden/yt-transcript-dl-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server