autoclear cache when it gets too big - fixes #2678

This commit is contained in:
Sebastian McKenzie
2015-11-03 10:57:32 +00:00
parent cdeff2fbb1
commit 8ffc7012cc

View File

@@ -13,7 +13,18 @@ let data = {};
*/
export function save() {
fs.writeFileSync(FILENAME, JSON.stringify(data, null, " "));
let serialised = {};
try {
serialised = JSON.stringify(data, null, " ");
} catch (err) {
if (err.message === "Invalid string length") {
err.message = "Cache too large so it's been cleared.";
console.error(err.stack);
} else {
throw err;
}
}
fs.writeFileSync(FILENAME, serialised);
}
/**