First try

This commit is contained in:
2026-01-13 11:12:51 +01:00
parent af44e50f54
commit 93485efc5c
16 changed files with 525 additions and 486 deletions

View File

@@ -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);
}