Fix cache-purging not working
This commit is contained in:
36
src/common/JsonFileManager.js
Normal file
36
src/common/JsonFileManager.js
Normal 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;
|
Reference in New Issue
Block a user