Skip to main content
Glama

Excel MCP Server

by zhiwei5576
MIT License
99
41
  • Linux
  • Apple
workbookCache.ts2.01 kB
import type { WorkBook } from 'xlsx' import type { EnsureWorkbookResult } from '../types/index.js' interface CacheItem { workbook: WorkBook; timestamp: number; } import { getConfig } from './config.js'; class WorkbookCache { private cache = new Map<string, CacheItem>(); private readonly maxAge: number; private readonly cleanupInterval: number; constructor() { const config = getConfig(); // 将小时转换为毫秒 this.maxAge = config.cache.maxAge * 60 * 60 * 1000; this.cleanupInterval = config.cache.cleanupInterval * 60 * 60 * 1000; // 创建定时器,定期清理过期缓存 setInterval(() => { const now = Date.now(); for (const [key, item] of this.cache.entries()) { if (now - item.timestamp > this.maxAge) { this.delete(key); } } }, this.cleanupInterval); } set(filePathWithName: string, workbook: WorkBook): void { this.cache.set(filePathWithName, { workbook, timestamp: Date.now() }); } get(filePathWithName: string): WorkBook | undefined { const item = this.cache.get(filePathWithName); if (!item) return undefined; // 检查是否过期 if (Date.now() - item.timestamp > this.maxAge) { this.delete(filePathWithName); return undefined; } return item.workbook; } ensureWorkbook(filePathWithName: string): EnsureWorkbookResult { const workbook = this.get(filePathWithName); if (!workbook) { return { success: false }; } return { success: true, data: workbook }; } // 删除工作簿 delete(filePathWithName: string): boolean { if (!this.cache.has(filePathWithName)) return false return this.cache.delete(filePathWithName) } // 清空缓存 clear(): void { this.cache.clear() } // 检查是否存在 has(filePathWithName: string): boolean { return this.cache.has(filePathWithName) } } export const workbookCache = new WorkbookCache();

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/zhiwei5576/excel-mcp-server'

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