ts-ioc-container
Version:
Typescript IoC container
39 lines (38 loc) • 940 B
JavaScript
;
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;