UNPKG

3.56 kBJavaScriptView Raw
1"use strict";
2var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3 if (kind === "m") throw new TypeError("Private method is not writable");
4 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5 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");
6 return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7};
8var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10 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");
11 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12};
13var _a, _Cache_instance, _Cache_enabled, _Cache_hits, _Cache_lookups;
14Object.defineProperty(exports, "__esModule", { value: true });
15exports.Cache = void 0;
16/*
17 * Copyright (c) 2020, salesforce.com, inc.
18 * All rights reserved.
19 * Licensed under the BSD 3-Clause license.
20 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
21 */
22class Cache extends Map {
23 /* eslint-enable @typescript-eslint/explicit-member-accessibility */
24 constructor() {
25 super();
26 _Cache_hits.set(this, void 0);
27 _Cache_lookups.set(this, void 0);
28 __classPrivateFieldSet(this, _Cache_hits, 0, "f");
29 __classPrivateFieldSet(this, _Cache_lookups, 0, "f");
30 }
31 static instance() {
32 if (!__classPrivateFieldGet(Cache, _a, "f", _Cache_instance)) {
33 __classPrivateFieldSet(Cache, _a, true, "f", _Cache_enabled);
34 __classPrivateFieldSet(Cache, _a, new Cache(), "f", _Cache_instance);
35 }
36 return __classPrivateFieldGet(Cache, _a, "f", _Cache_instance);
37 }
38 static set(key, value) {
39 if (__classPrivateFieldGet(Cache, _a, "f", _Cache_enabled)) {
40 Cache.instance().set(key, value);
41 }
42 }
43 static get(key) {
44 var _b, _c, _d;
45 if (!__classPrivateFieldGet(Cache, _a, "f", _Cache_enabled)) {
46 return undefined;
47 }
48 __classPrivateFieldSet(_b = Cache.instance(), _Cache_lookups, (_c = __classPrivateFieldGet(_b, _Cache_lookups, "f"), _c++, _c), "f");
49 __classPrivateFieldSet(_d = Cache.instance(), _Cache_hits, __classPrivateFieldGet(_d, _Cache_hits, "f") + (Cache.instance().has(key) ? 1 : 0), "f");
50 return __classPrivateFieldGet(Cache, _a, "f", _Cache_instance).get(key);
51 }
52 static disable() {
53 __classPrivateFieldSet(Cache, _a, false, "f", _Cache_enabled);
54 }
55 static enable() {
56 __classPrivateFieldSet(Cache, _a, true, "f", _Cache_enabled);
57 }
58 static get hits() {
59 return __classPrivateFieldGet(Cache.instance(), _Cache_hits, "f");
60 }
61 static get lookups() {
62 return __classPrivateFieldGet(Cache.instance(), _Cache_lookups, "f");
63 }
64}
65exports.Cache = Cache;
66_a = Cache, _Cache_hits = new WeakMap(), _Cache_lookups = new WeakMap();
67/* eslint-disable @typescript-eslint/explicit-member-accessibility */
68_Cache_instance = { value: void 0 };
69_Cache_enabled = { value: true };
70//# sourceMappingURL=cache.js.map
\No newline at end of file