mirror of
https://github.com/2234839/web-font.git
synced 2026-05-16 02:38:11 +08:00
- 新增通用 LruCache 类,支持按条目数/字节容量两种淘汰策略 - 字体裁剪结果 LRU 内存缓存(默认 10MB,X-Cache 响应头标识命中) - 新增 GET /api/stats 运行时统计接口 - 前端统计面板(10s 轮询,页面不可见时暂停) - API handler 拆分到 routes/ 目录,提取 shared.ts 共享模块 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
18 lines
581 B
TypeScript
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,
|
|
}),
|
|
};
|
|
}
|