/** * 模型缓存模块 * 提供模型和结果的缓存功能 */ import { OCRImageData as ImageData } from "./image"; export interface CacheOptions { /** 缓存大小限制 (MB) */ maxSize?: number; /** 缓存条目数量限制 */ maxCount?: number; /** 缓存过期时间 (ms) */ ttl?: number; /** 是否启用结果缓存 */ enableResultCache?: boolean; /** 是否启用模型缓存 */ enableModelCache?: boolean; } /** * LRU 缓存实现 */ export declare class ModelCache { private cache; private options; private currentSize; constructor(options?: CacheOptions); /** * 设置缓存 */ set(key: string, value: T, size?: number): void; /** * 获取缓存 */ get(key: string): T | undefined; /** * 检查缓存是否存在 */ has(key: string): boolean; /** * 删除缓存 */ delete(key: string): boolean; /** * 清空缓存 */ clear(): void; /** * 获取缓存统计 */ getStats(): { size: number; count: number; hitRate: number; totalHits: number; }; /** * 估计数据大小 */ private estimateSize; /** * 淘汰最少使用的条目 */ private evict; } /** * 图像缓存 */ export declare class ImageCache { private cache; constructor(options?: CacheOptions); /** * 缓存图像 */ set(key: string, imageData: ImageData): void; /** * 获取缓存的图像 */ get(key: string): ImageData | undefined; /** * 检查缓存 */ has(key: string): boolean; /** * 生成图像缓存键 */ static generateKey(source: string | Uint8Array, options?: { width?: number; height?: number; threshold?: number; }): string; /** * 简单哈希函数 */ private static hashString; /** * 数组转字符串 */ private static arrayToString; /** * 清空缓存 */ clear(): void; /** * 获取统计信息 */ getStats(): { size: number; count: number; hitRate: number; totalHits: number; }; } /** * 结果缓存 */ export declare class ResultCache { private cache; constructor(options?: CacheOptions); /** * 生成结果缓存键 */ static generateKey(imageHash: string, options?: { mode?: string; threshold?: number; language?: string; }): string; private static hashString; /** * 缓存结果 */ set(key: string, result: any): void; /** * 获取缓存结果 */ get(key: string): any; /** * 检查缓存 */ has(key: string): boolean; /** * 清空缓存 */ clear(): void; /** * 获取统计信息 */ getStats(): { size: number; count: number; hitRate: number; totalHits: number; }; } /** * 创建模型缓存 */ export declare function createModelCache(options?: CacheOptions): ModelCache; /** * 创建图像缓存 */ export declare function createImageCache(options?: CacheOptions): ImageCache; /** * 创建结果缓存 */ export declare function createResultCache(options?: CacheOptions): ResultCache; declare const _default: { ModelCache: typeof ModelCache; ImageCache: typeof ImageCache; ResultCache: typeof ResultCache; createModelCache: typeof createModelCache; createImageCache: typeof createImageCache; createResultCache: typeof createResultCache; }; export default _default;