/** * 外挂识图缓存(图片内容 → 文字描述) * * 存储位置:~/.llm-proxy/vision-cache.json * - base64 图片:键 = "md5:" + md5(mediaType + data) * - URL 图片: 键 = "url:" + 原 URL * - 值 = { desc, lastUsedAt }(lastUsedAt 用于 LRU 淘汰) * * 容量策略:默认上限 1000 条,超过按 lastUsedAt 升序淘汰 * 写盘策略:内存变更后 5s 防抖 flush;进程退出前同步 flush * 统计:hits / misses(每次 miss 累加,命中时同时更新 lastUsedAt) */ export interface CacheEntry { desc: string; /** LRU 时间戳(ms)——命中或写入时更新 */ lastUsedAt: number; } export interface CacheStats { hits: number; misses: number; size: number; maxEntries: number; hitRate: number; } export interface VisionCacheOptions { filePath: string; maxEntries?: number; } /** * 计算图片键。 * - data URI("data:;base64,"):md5(mediaType + data) * - http(s) URL:原 URL 自身 * - 其他原样返回(理论上不应出现) */ export declare function computeImageKey(url: string): string; export declare class VisionCache { private readonly filePath; private readonly maxEntries; private map; private dirty; private flushTimer; private hits; private misses; constructor(opts: VisionCacheOptions); /** 启动时从磁盘加载(不存在或损坏时静默以空缓存开始) */ load(): void; /** * 查询缓存。命中时同步更新 lastUsedAt 与 hits 计数,并标记 dirty。 * 返回描述文本;未命中返回 null。 */ get(key: string): string | null; /** * 写入缓存。超容量时按 LRU 淘汰。 * 注意:写入不增加 hits 计数(hits 仅用于查询命中统计)。 */ set(key: string, desc: string): void; /** 清空缓存:内存 + 磁盘 + 计数 */ clear(): Promise; getStats(): CacheStats; /** 防抖 flush:set/get 之后调用 */ private markDirty; /** 同步写盘(用于 SIGTERM 等退出路径) */ flushSync(): void; /** 异步写盘(防抖定时器触发) */ private writeJson; private serialize; /** 按 lastUsedAt 升序淘汰 n 条 */ private evictOldest; } //# sourceMappingURL=vision-cache.d.ts.map