blob: 157e7346dfba863ed5409b10b07da0aaa155b153 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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 = {};
}
}
|