Move cache files to their own directory

This commit is contained in:
Matt Isenhower 2022-09-09 14:55:30 -07:00
parent 084793948f
commit 314d61ecb4
3 changed files with 6 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import fs from 'fs/promises';
import path from 'path';
import mkdirp from 'mkdirp';
export default class ValueCache
{
constructor(key) {
@ -7,7 +8,7 @@ export default class ValueCache
}
get path() {
return `storage/${this._key}.json`;
return `storage/cache/${this._key}.json`;
}
async _getRawItem() {
@ -40,6 +41,7 @@ export default class ValueCache
async setData(data, expires = null) {
let serialized = JSON.stringify({ expires, data }, undefined, 2);
await mkdirp(path.dirname(this.path));
await fs.writeFile(this.path, serialized);
}
}

1
package-lock.json generated
View File

@ -11,6 +11,7 @@
"cron": "^2.1.0",
"dotenv": "^16.0.2",
"ecstatic": "^4.1.4",
"mkdirp": "^1.0.4",
"nxapi": "^1.4.0",
"pinia": "^2.0.13",
"puppeteer": "^17.0.0",

View File

@ -13,6 +13,7 @@
"cron": "^2.1.0",
"dotenv": "^16.0.2",
"ecstatic": "^4.1.4",
"mkdirp": "^1.0.4",
"nxapi": "^1.4.0",
"pinia": "^2.0.13",
"puppeteer": "^17.0.0",