import {ICache} from './cache.interface'; import {ISerializable} from './serializeable.interface'; import {Injectable} from '@angular/core'; @Injectable() export class MemoryCacheService implements ICache { private memoryCache = new Map(); get(key: string, type: {new(): ISerializable}): T { return this.restore(key, new type()); } restore(key: string, restoreInto: ISerializable): T { return this.memoryCache.get(key); } set(key: string, data: ISerializable): string { this.memoryCache.set(key, data); return key; } delete(key: string): boolean { const exists = this.keyExists(key); if (exists) { this.memoryCache.delete(key); } return exists; } clear(): void { this.memoryCache.clear(); } keyExists(key: string): boolean { return !!this.memoryCache.get(key); } }