| 334 | // persistence |
| 335 | // initialize cache |
| 336 | initCache() { |
| 337 | if (isQX) this.cache = JSON.parse($prefs.valueForKey(this.name) || "{}"); |
| 338 | if (isLoon || isSurge) |
| 339 | this.cache = JSON.parse($persistentStore.read(this.name) || "{}"); |
| 340 | |
| 341 | if (isNode) { |
| 342 | // create a json for root cache |
| 343 | let fpath = "root.json"; |
| 344 | if (!this.node.fs.existsSync(fpath)) { |
| 345 | this.node.fs.writeFileSync( |
| 346 | fpath, |
| 347 | JSON.stringify({}), |
| 348 | { |
| 349 | flag: "wx", |
| 350 | }, |
| 351 | (err) => console.log(err) |
| 352 | ); |
| 353 | } |
| 354 | this.root = {}; |
| 355 | |
| 356 | // create a json file with the given name if not exists |
| 357 | fpath = `${this.name}.json`; |
| 358 | if (!this.node.fs.existsSync(fpath)) { |
| 359 | this.node.fs.writeFileSync( |
| 360 | fpath, |
| 361 | JSON.stringify({}), |
| 362 | { |
| 363 | flag: "wx", |
| 364 | }, |
| 365 | (err) => console.log(err) |
| 366 | ); |
| 367 | this.cache = {}; |
| 368 | } else { |
| 369 | this.cache = JSON.parse( |
| 370 | this.node.fs.readFileSync(`${this.name}.json`) |
| 371 | ); |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | // store cache |
| 377 | persistCache() { |