Skip to content

Commit

Permalink
feat: log when flush to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
KatoakDR committed Jan 22, 2024
1 parent 42488ab commit cc8d25c
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions electron/main/cache/disk-cache.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,24 @@ export class DiskCacheServiceImpl extends AbstractCacheService {

private createDebouncedWriteToDisk(): DebouncedFunc<() => Promise<void>> {
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<void> {
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<T>(key: string, item: T): Promise<void> {
await this.delegate.set(key, item);
await this.writeToDisk();
Expand Down

0 comments on commit cc8d25c

Please sign in to comment.