崮生(子虚) c18dc44e72 chore: 升级至 v1.7.0,新增内存缓存与运行时统计
- 新增通用 LruCache 类,支持按条目数/字节容量两种淘汰策略
- 字体裁剪结果 LRU 内存缓存(默认 10MB,X-Cache 响应头标识命中)
- 新增 GET /api/stats 运行时统计接口
- 前端统计面板(10s 轮询,页面不可见时暂停)
- API handler 拆分到 routes/ 目录,提取 shared.ts 共享模块

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 19:34:30 +08:00

18 lines
581 B
TypeScript

import { jsonResponse, stats, subsetCache, fontBufferCache } from "../shared";
/** GET /api/stats — 返回运行时统计 */
export async function handleStats(req: Request, res: Response) {
return {
req,
res: jsonResponse({
uptime: Math.floor((Date.now() - stats.startTime) / 1000),
totalRequests: stats.totalRequests,
subsetRequests: stats.subsetRequests,
subsetCacheHits: stats.subsetCacheHits,
totalChars: stats.totalChars,
subsetCacheEntries: subsetCache.size,
fontBufferCacheEntries: fontBufferCache.size,
}),
};
}