add schema version to cache file

This commit is contained in:
Conduitry 2020-10-15 07:37:52 -04:00
parent 6322103fc7
commit 9b44f7c9d6
1 changed files with 9 additions and 7 deletions

View File

@ -14,12 +14,14 @@ export const autocache = (path: string, mode: Mode) => {
(loading = promises
.readFile(path)
.then(deserialize)
.then((data: Cache) => {
cache = data;
for (const [key, [, modes]] of cache) {
modes.delete(mode);
if (modes.size === 0) {
removing.add(key);
.then((data) => {
if (data && typeof data === 'object' && data.schema === 1 && data.cache instanceof Map) {
cache = data.cache;
for (const [key, [, modes]] of cache) {
modes.delete(mode);
if (modes.size === 0) {
removing.add(key);
}
}
}
})
@ -45,7 +47,7 @@ export const autocache = (path: string, mode: Mode) => {
for (const key of removing) {
cache.delete(key);
}
writeFileSync(path, serialize(cache));
writeFileSync(path, serialize({ schema: 1, cache }));
},
};
};