type ID = string | number export class ContextCache { private cache: { [key: string]: any } = {} public getCacheKey(type: string, id: ID): string { return `${type}:${id}` } public add(key: string, element: B): void { this.cache[key] = element } public get(key: string, init?: () => Promise): B | Promise { if (!this.cache[key] && init) { const result = init() void result.then(r => { this.cache[key] = r }) return result } return this.cache[key] } }