Fix cache-purging not working

This commit is contained in:
Yuya Ochiai
2018-01-18 00:14:33 +09:00
parent 52559111fa
commit 4caf906ad6
3 changed files with 62 additions and 4 deletions

View File

@@ -0,0 +1,36 @@
const fs = require('fs');
class JsonFileManager {
constructor(file) {
this.jsonFile = file;
try {
this.json = JSON.parse(fs.readFileSync(file, 'utf-8'));
} catch (err) {
this.json = {};
}
}
writeToFile() {
fs.writeFile(this.jsonFile, JSON.stringify(this.json, null, 2), (err) => {
if (err) {
console.error(err);
}
});
}
setJson(json) {
this.json = json;
this.writeToFile();
}
setValue(key, value) {
this.json[key] = value;
this.writeToFile();
}
getValue(key) {
return this.json[key];
}
}
module.exports = JsonFileManager;