Commit 642e4446 authored by Shane Eckenrode's avatar Shane Eckenrode

Add expiration check to cache get to ensure expired data isn't returned

parent a72a477f
Pipeline #75672 passed with stages
in 3 minutes and 30 seconds
......@@ -17,13 +17,15 @@ export class RequestCache {
const url = req.urlWithParams;
const cached = this.cache.get(url);
return !!cached ? cached.response : undefined;
const isExpired = cached.expireTime.getTime() < Date.now();
return !!cached && !isExpired ? cached.response : undefined;
}
put(req: HttpRequest<any>, expireTime: Date, response: HttpResponse<any>, requestTag: string): void {
const url = req.urlWithParams;
const entry = { url, response, expireTime, invalidationTag: requestTag };
console.log('adding new entry to RequestCache map: ', entry);
console.log('Adding new entry to cache: ', entry);
this.cache.set(url, entry);
// Clean out expired entries
......@@ -32,6 +34,8 @@ export class RequestCache {
this.cache.delete(expiredEntry.url);
}
});
console.log('Current RequestCache: ', this.cache);
}
invalidateChangedResourceKeys(req: HttpRequest<any>): void {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment