UNPKG

ts-ioc-container

Version:
39 lines (38 loc) 940 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SingleCache = exports.multiCache = exports.MultiCache = void 0; class MultiCache { getKey; instances = new Map(); constructor(getKey = () => '1') { this.getKey = getKey; } hasValue(token) { return this.instances.has(token); } getValue(token) { return this.instances.get(token); } setValue(token, value) { this.instances.set(token, value); } } exports.MultiCache = MultiCache; const multiCache = (getKey) => new MultiCache(getKey); exports.multiCache = multiCache; class SingleCache { instance; getKey(...args) { return '1'; } getValue(key) { return this.instance.value; } hasValue(key) { return this.instance !== undefined; } setValue(key, value) { this.instance = { value }; } } exports.SingleCache = SingleCache;