From cc8d25c5c6613d9aa336e2beb0c0c14779889998 Mon Sep 17 00:00:00 2001 From: KatoakDR <68095633+KatoakDR@users.noreply.github.com> Date: Mon, 22 Jan 2024 01:58:42 -0600 Subject: [PATCH] feat: log when flush to disk --- electron/main/cache/disk-cache.service.ts | 25 ++++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/electron/main/cache/disk-cache.service.ts b/electron/main/cache/disk-cache.service.ts index c997a3ee..1f74db04 100644 --- a/electron/main/cache/disk-cache.service.ts +++ b/electron/main/cache/disk-cache.service.ts @@ -54,19 +54,24 @@ export class DiskCacheServiceImpl extends AbstractCacheService { private createDebouncedWriteToDisk(): DebouncedFunc<() => Promise> { return debounce(async () => { - const { filepath } = this.options; - try { - const cache = await this.delegate.readCache(); - await fs.writeJson(filepath, cache); - } catch (error) { - logger.error('error writing cache to disk', { - filepath, - error, - }); - } + await this.writeToDiskNow(); }, 1000); } + private async writeToDiskNow(): Promise { + const { filepath } = this.options; + try { + const cache = await this.delegate.readCache(); + await fs.writeJson(filepath, cache); + logger.debug('wrote cache to disk'); + } catch (error) { + logger.error('error writing cache to disk', { + filepath, + error, + }); + } + } + public async set(key: string, item: T): Promise { await this.delegate.set(key, item); await this.writeToDisk();