Skip to content

Commit

Permalink
Fix: save the file cache on exit (#1236)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Jul 25, 2024
1 parent 29a3482 commit c114188
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/types/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export default class Cache<V> {
this.fileFlushMillis = props?.fileFlushMillis;
if (props?.saveOnExit) {
// WARN: Jest won't call this: https://github.com/jestjs/jest/issues/10927
process.once('beforeExit', this.save);
process.once('beforeExit', async () => {
await this.save();
});
}
this.maxSize = props?.maxSize;
}
Expand Down
1 change: 1 addition & 0 deletions src/types/files/fileCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default class FileCache {
this.cache = await new Cache<CacheValue>({
filePath,
fileFlushMillis: 30_000,
saveOnExit: true,
}).load();

// Cleanup the loaded cache file
Expand Down

0 comments on commit c114188

Please sign in to comment.