diff options
Diffstat (limited to 'ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/services/cache.service.ts')
-rw-r--r-- | ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/services/cache.service.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/services/cache.service.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/services/cache.service.ts new file mode 100644 index 00000000..157e7346 --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/services/cache.service.ts @@ -0,0 +1,59 @@ +import {HttpRequest, HttpResponse} from '@angular/common/http'; +import {Injectable} from '@angular/core'; + +abstract class HttpCache { + abstract get(req: HttpRequest<any>): HttpResponse<any> | null; + + abstract put(req: HttpRequest<any>, resp: HttpResponse<any>): void; + + abstract clearCache(): void; +} + +@Injectable() +export class HttpCacheService implements HttpCache { + + private cache = {}; + private previousIdList = {}; + private routeCache = {}; + private routeGroupSelectCache = {}; + + get(req: HttpRequest<any>): HttpResponse<any> | null { + return this.cache[req.urlWithParams]; + } + + put(req: HttpRequest<any>, resp: HttpResponse<any>): 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 = {}; + } +} |