debounced cache persist — at most once every 10s
()
| 145 | if (this.cacheDb.data.cache) { |
| 146 | for (const [k, v] of Object.entries(this.cacheDb.data.cache)) |
| 147 | this.chatCache.set(k, v as CachedChat); |
| 148 | console.log(`[fbi] cache loaded: ${this.chatCache.size} groups`); |
| 149 | } |
| 150 | } catch (e: unknown) { |
| 151 | console.error("[fbi] initDB cache load failed, resetting cache.json", e); |
| 152 | try { |
| 153 | const fs = await import("fs"); |
| 154 | if (fs.existsSync(cp)) { |
| 155 | fs.renameSync(cp, `${cp}.corrupt.${Date.now()}`); |
| 156 | } |
| 157 | } catch (_renameErr: unknown) { |
| 158 | /* ignore rename failure; overwrite below */ |
| 159 | } |
| 160 | this.chatCache.clear(); |