- 数据库表规范化与原子事务版本迁移机制 (_schema_migrations) - 增加 SQLite 复合主键、PRAGMA busy_timeout 与索引覆盖 - 构建统一两级协同缓存 (L1 Memory LRU + L2 SQLite 持久化) - withCache 增加 In-flight Promise 去重并发防击穿 (单飞机制) - 收敛 dimension、role、bill 与 token-store 缓存逻辑 - 100% 保持现有 API 契约与零功能删除
36 lines
873 B
TypeScript
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;
|
|
}
|
|
}
|