First try
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpRequest, HttpResponse } from '@angular/common/http';
|
||||
import { Injectable } from "@angular/core";
|
||||
import { HttpRequest, HttpResponse } from "@angular/common/http";
|
||||
|
||||
@Injectable()
|
||||
export class RequestCache {
|
||||
@@ -10,8 +10,8 @@ export class RequestCache {
|
||||
}
|
||||
|
||||
get(req: HttpRequest<any>): HttpResponse<any> | undefined {
|
||||
const splittedUrl = req.urlWithParams.split('/');
|
||||
const url = splittedUrl[splittedUrl.length - 1] + '_' + req.method;
|
||||
const splittedUrl = req.urlWithParams.split("/");
|
||||
const url = splittedUrl[splittedUrl.length - 1] + "_" + req.method;
|
||||
this.clearExpiredEntries();
|
||||
const cached = this.cache.get(url);
|
||||
|
||||
@@ -24,8 +24,8 @@ export class RequestCache {
|
||||
}
|
||||
|
||||
put(req: HttpRequest<any>, response: HttpResponse<any>): void {
|
||||
const splittedUrl = req.urlWithParams.split('/');
|
||||
const url = splittedUrl[splittedUrl.length - 1] + '_' + req.method;
|
||||
const splittedUrl = req.urlWithParams.split("/");
|
||||
const url = splittedUrl[splittedUrl.length - 1] + "_" + req.method;
|
||||
|
||||
const entry = { url, response, lastRead: Date.now() };
|
||||
this.cache.set(url, entry);
|
||||
@@ -36,7 +36,7 @@ export class RequestCache {
|
||||
const maxAge = 30000;
|
||||
const expired = Date.now() - maxAge;
|
||||
|
||||
this.cache.forEach(expiredEntry => {
|
||||
this.cache.forEach((expiredEntry) => {
|
||||
if (expiredEntry.lastRead < expired) {
|
||||
this.cache.delete(expiredEntry.url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user