MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / CacheManager

Class CacheManager

aban/aban.ts:103–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101 private static instance: CacheManager;
102 private initPromise: Promise<void>;
103
104 private constructor() {
105 this.initPromise = this.initDb();
106 }
107
108 static getInstance(): CacheManager {
109 if (!this.instance) {
110 this.instance = new CacheManager();
111 }
112 return this.instance;
113 }
114
115 private async initDb(): Promise<void> {
116 const dbPath = path.join(
117 createDirectoryInAssets("aban"),
118 CONFIG.CACHE_DB_NAME
119 );
120 const adapter = new JSONFile<CacheData>(dbPath);
121 this.db = new Low(adapter, { cache: {} });
122 await this.db.read();
123 if (!this.db.data) {
124 this.db.data = { cache: {} };
125 await this.db.write();
126 }
127 }
128
129 async get(key: string): Promise<any> {
130 await this.initPromise;
131 if (!this.db) return null;
132 return this.db.data.cache[key] || null;
133 }
134
135 async set(key: string, value: any): Promise<void> {
136 await this.initPromise;
137 if (!this.db) return;
138 this.db.data.cache[key] = value;
139 await this.db.write();
140 }
141
142 async clear(): Promise<void> {
143 await this.initPromise;
144 if (!this.db) return;
145 this.db.data.cache = {};
146 await this.db.write();
147 }
148}
149
150// ==================== 用户解析器 ====================
151type ResolvedTarget = {
152 user: any;
153 uid: number | null;
154 participant?: any;
155 source: "reply" | "username" | "numeric" | "unknown";

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected