@experteam-mx/ngx-services 20.3.6-dev1.0 → 20.3.6-dev1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,7 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { InjectionToken, makeEnvironmentProviders, NgModule, inject, Injectable } from '@angular/core';
|
|
3
3
|
import { provideHttpClient, HttpClient, HttpHeaders, HttpResponse, HttpParams } from '@angular/common/http';
|
|
4
4
|
import { map, mergeMap, forkJoin, tap, Observable, of } from 'rxjs';
|
|
5
|
-
import { map as map$1, tap as tap$1 } from 'rxjs/operators';
|
|
5
|
+
import { map as map$1, tap as tap$1, finalize, shareReplay } from 'rxjs/operators';
|
|
6
6
|
import { CookieService } from 'ngx-cookie-service';
|
|
7
7
|
import Pusher from 'pusher-js';
|
|
8
8
|
|
|
@@ -5350,6 +5350,7 @@ function apiTokenInterceptor(req, next) {
|
|
|
5350
5350
|
|
|
5351
5351
|
const DEFAULT_TTL = 10000; // ttl in ms
|
|
5352
5352
|
const cache = new Map();
|
|
5353
|
+
const inFlightRequests = new Map();
|
|
5353
5354
|
/**
|
|
5354
5355
|
* Interceptor function to handle HTTP caching for GET requests. It retrieves cached responses
|
|
5355
5356
|
* if available and valid; otherwise, it processes the request and caches the response for future use.
|
|
@@ -5363,21 +5364,30 @@ function httpCachingInterceptor(req, next) {
|
|
|
5363
5364
|
const { cacheTtl } = inject(ENVIRONMENT_TOKEN);
|
|
5364
5365
|
if (req.method !== 'GET')
|
|
5365
5366
|
return next(req);
|
|
5366
|
-
const
|
|
5367
|
+
const key = req.urlWithParams;
|
|
5368
|
+
const cached = cache.get(key);
|
|
5367
5369
|
if (cached) {
|
|
5368
5370
|
const isExpired = Date.now() > cached.ttl;
|
|
5369
5371
|
if (!isExpired) {
|
|
5370
5372
|
return of(cached.res);
|
|
5371
5373
|
}
|
|
5372
|
-
cache.delete(
|
|
5374
|
+
cache.delete(key); // If expired, remove the entry from cache
|
|
5373
5375
|
}
|
|
5374
|
-
|
|
5376
|
+
const inFlight = inFlightRequests.get(key);
|
|
5377
|
+
if (inFlight) {
|
|
5378
|
+
return inFlight;
|
|
5379
|
+
}
|
|
5380
|
+
const sharedRequest = next(req).pipe(tap$1((res) => {
|
|
5375
5381
|
if (!(res instanceof HttpResponse)) {
|
|
5376
5382
|
return;
|
|
5377
5383
|
}
|
|
5378
5384
|
const ttl = Date.now() + (cacheTtl ?? DEFAULT_TTL);
|
|
5379
|
-
cache.set(
|
|
5380
|
-
}))
|
|
5385
|
+
cache.set(key, { res, ttl });
|
|
5386
|
+
}), finalize(() => {
|
|
5387
|
+
inFlightRequests.delete(key);
|
|
5388
|
+
}), shareReplay(1));
|
|
5389
|
+
inFlightRequests.set(key, sharedRequest);
|
|
5390
|
+
return sharedRequest;
|
|
5381
5391
|
}
|
|
5382
5392
|
|
|
5383
5393
|
const base64PdfToUrl = (base64) => {
|