enh(Placekeeper) simplify option name
This commit is contained in:
@@ -13,7 +13,7 @@ export default class Placekeeper {
|
|||||||
#cache = new Map();
|
#cache = new Map();
|
||||||
#options = new Map([
|
#options = new Map([
|
||||||
['cacheDir', undefined],
|
['cacheDir', undefined],
|
||||||
['deactivateCache', false],
|
['disableCache', false],
|
||||||
['safeNames', []],
|
['safeNames', []],
|
||||||
['onError', (err) => {}],
|
['onError', (err) => {}],
|
||||||
]);
|
]);
|
||||||
@@ -174,7 +174,7 @@ export default class Placekeeper {
|
|||||||
* @param {string} cacheableRepresentation - The JSON representation of the template parts.
|
* @param {string} cacheableRepresentation - The JSON representation of the template parts.
|
||||||
*/
|
*/
|
||||||
async store(filePath) {
|
async store(filePath) {
|
||||||
if(!this.#options.get('cacheDir') || this.#options.get('deactivateCache')) return true;
|
if(!this.#options.get('cacheDir') || this.#options.get('disableCache')) return true;
|
||||||
const key = this.#cleanKey(filePath);
|
const key = this.#cleanKey(filePath);
|
||||||
await Placekeeper.storage.ensureDir(this.#options.get('cacheDir'));
|
await Placekeeper.storage.ensureDir(this.#options.get('cacheDir'));
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ export default class Placekeeper {
|
|||||||
*/
|
*/
|
||||||
async load(filePath) {
|
async load(filePath) {
|
||||||
if(typeof(filePath) != 'string') throw new TypeError(`filepath is not a string!`);
|
if(typeof(filePath) != 'string') throw new TypeError(`filepath is not a string!`);
|
||||||
if(!this.#options.get('cacheDir') || this.#options.get('deactivateCache')) return null;
|
if(!this.#options.get('cacheDir') || this.#options.get('disableCache')) return null;
|
||||||
const key = this.#cleanKey(filePath);
|
const key = this.#cleanKey(filePath);
|
||||||
let cacheFilePath = this.buildPath(this.#options.get('cacheDir'), `${key}.json`);
|
let cacheFilePath = this.buildPath(this.#options.get('cacheDir'), `${key}.json`);
|
||||||
|
|
||||||
@@ -308,7 +308,7 @@ export default class Placekeeper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const template = this.#cache.get(key);
|
const template = this.#cache.get(key);
|
||||||
if(this.#options.get('deactivateCache')) this.#cache.delete(key);
|
if(this.#options.get('disableCache')) this.#cache.delete(key);
|
||||||
if (!template) {
|
if (!template) {
|
||||||
throw new Error(`Template with key '${key}' not found in cache.`);
|
throw new Error(`Template with key '${key}' not found in cache.`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user