UNPKG

@salesforce/core

Version:

Core libraries to interact with SFDX projects, orgs, and APIs.

56 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Cache = void 0; /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ class Cache extends Map { /* eslint-disable @typescript-eslint/explicit-member-accessibility */ static #instance; static #enabled = true; #hits; #lookups; /* eslint-enable @typescript-eslint/explicit-member-accessibility */ constructor() { super(); this.#hits = 0; this.#lookups = 0; } static get hits() { return Cache.instance().#hits; } static get lookups() { return Cache.instance().#lookups; } static instance() { if (!Cache.#instance) { Cache.#enabled = true; Cache.#instance = new Cache(); } return Cache.#instance; } static set(key, value) { if (Cache.#enabled) { Cache.instance().set(key, value); } } static get(key) { if (!Cache.#enabled) { return undefined; } Cache.instance().#lookups++; Cache.instance().#hits += Cache.instance().has(key) ? 1 : 0; return Cache.#instance.get(key); } static disable() { Cache.#enabled = false; } static enable() { Cache.#enabled = true; } } exports.Cache = Cache; //# sourceMappingURL=cache.js.map