enh(Placekeeper) simplify option name

This commit is contained in:
gh0sTedBuddy
2024-04-01 23:15:27 +01:00
parent 6855de5997
commit 483411e4cf

View File

@@ -13,7 +13,7 @@ export default class Placekeeper {
#cache = new Map();
#options = new Map([
['cacheDir', undefined],
['deactivateCache', false],
['disableCache', false],
['safeNames', []],
['onError', (err) => {}],
]);
@@ -174,7 +174,7 @@ export default class Placekeeper {
* @param {string} cacheableRepresentation - The JSON representation of the template parts.
*/
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);
await Placekeeper.storage.ensureDir(this.#options.get('cacheDir'));
@@ -229,7 +229,7 @@ export default class Placekeeper {
*/
async load(filePath) {
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);
let cacheFilePath = this.buildPath(this.#options.get('cacheDir'), `${key}.json`);
@@ -308,7 +308,7 @@ export default class Placekeeper {
}
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) {
throw new Error(`Template with key '${key}' not found in cache.`);
}