Files
hose-use/src/core/cache/index.ts
T
gitea 3a15b064fe refactor(core): 规范数据库表结构、版本迁移与多级缓存体系加固
- 数据库表规范化与原子事务版本迁移机制 (_schema_migrations)
- 增加 SQLite 复合主键、PRAGMA busy_timeout 与索引覆盖
- 构建统一两级协同缓存 (L1 Memory LRU + L2 SQLite 持久化)
- withCache 增加 In-flight Promise 去重并发防击穿 (单飞机制)
- 收敛 dimension、role、bill 与 token-store 缓存逻辑
- 100% 保持现有 API 契约与零功能删除
2026-09-08 15:49:27 +08:00

36 lines
873 B
TypeScript

import { MultiLevelCache, type MultiLevelCacheOptions } from "./multi-level.js";
export * from "./types.js";
export * from "./memory.js";
export * from "./sqlite.js";
export * from "./multi-level.js";
let defaultCacheInstance: MultiLevelCache | null = null;
/**
* 获取全局默认多级缓存实例(单例)
*/
export function getGlobalCache(): MultiLevelCache {
if (!defaultCacheInstance) {
defaultCacheInstance = new MultiLevelCache();
}
return defaultCacheInstance;
}
/**
* 创建独立的多级缓存实例
*/
export function createMultiLevelCache(options?: MultiLevelCacheOptions): MultiLevelCache {
return new MultiLevelCache(options);
}
/**
* 重置全局缓存实例(测试清理用)
*/
export function resetGlobalCache(): void {
if (defaultCacheInstance) {
defaultCacheInstance.clear();
defaultCacheInstance = null;
}
}