import {HttpRequest, HttpResponse} from '@angular/common/http'; import {Injectable} from '@angular/core'; abstract class HttpCache { abstract get(req: HttpRequest): HttpResponse | null; abstract put(req: HttpRequest, resp: HttpResponse): void; abstract clearCache(): void; } @Injectable() export class HttpCacheService implements HttpCache { private cache = {}; private previousIdList = {}; private routeCache = {}; private routeGroupSelectCache = {}; get(req: HttpRequest): HttpResponse | null { return this.cache[req.urlWithParams]; } put(req: HttpRequest, resp: HttpResponse): void { this.cache[req.urlWithParams] = resp; } getPreviousId(id: string): string | null { return this.previousIdList[id]; } setPreviousId(id: string, prev: string): void { this.previousIdList[id] = prev; } getRouteCache(id: string): string | null { return this.routeCache[id]; } setRouteCache(id: string, route: string): void { this.routeCache[id] = route; } getRouteGroupCache(id: string): string | null { return this.routeGroupSelectCache[id]; } setRouteGroupCache(id: string, group: string): void { this.routeGroupSelectCache[id] = group; } clearCache(): void { this.cache = {}; this.previousIdList = {}; this.routeCache = {}; this.routeGroupSelectCache = {}; } }