UNPKG

@salesforce/core

Version:

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

70 lines 3.56 kB
"use strict"; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _a, _Cache_instance, _Cache_enabled, _Cache_hits, _Cache_lookups; 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-enable @typescript-eslint/explicit-member-accessibility */ constructor() { super(); _Cache_hits.set(this, void 0); _Cache_lookups.set(this, void 0); __classPrivateFieldSet(this, _Cache_hits, 0, "f"); __classPrivateFieldSet(this, _Cache_lookups, 0, "f"); } static get hits() { return __classPrivateFieldGet(Cache.instance(), _Cache_hits, "f"); } static get lookups() { return __classPrivateFieldGet(Cache.instance(), _Cache_lookups, "f"); } static instance() { if (!__classPrivateFieldGet(Cache, _a, "f", _Cache_instance)) { __classPrivateFieldSet(Cache, _a, true, "f", _Cache_enabled); __classPrivateFieldSet(Cache, _a, new Cache(), "f", _Cache_instance); } return __classPrivateFieldGet(Cache, _a, "f", _Cache_instance); } static set(key, value) { if (__classPrivateFieldGet(Cache, _a, "f", _Cache_enabled)) { Cache.instance().set(key, value); } } static get(key) { var _b, _c, _d; if (!__classPrivateFieldGet(Cache, _a, "f", _Cache_enabled)) { return undefined; } __classPrivateFieldSet(_b = Cache.instance(), _Cache_lookups, (_c = __classPrivateFieldGet(_b, _Cache_lookups, "f"), _c++, _c), "f"); __classPrivateFieldSet(_d = Cache.instance(), _Cache_hits, __classPrivateFieldGet(_d, _Cache_hits, "f") + (Cache.instance().has(key) ? 1 : 0), "f"); return __classPrivateFieldGet(Cache, _a, "f", _Cache_instance).get(key); } static disable() { __classPrivateFieldSet(Cache, _a, false, "f", _Cache_enabled); } static enable() { __classPrivateFieldSet(Cache, _a, true, "f", _Cache_enabled); } } exports.Cache = Cache; _a = Cache, _Cache_hits = new WeakMap(), _Cache_lookups = new WeakMap(); /* eslint-disable @typescript-eslint/explicit-member-accessibility */ _Cache_instance = { value: void 0 }; _Cache_enabled = { value: true }; //# sourceMappingURL=cache.js.map