ts-ioc-container
Version:
Typescript IoC container
33 lines (32 loc) • 711 B
JavaScript
export 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);
}
}
export const multiCache = (getKey) => new MultiCache(getKey);
export 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 };
}
}