ng-http-caching 13.0.1 → 13.0.4
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.
- package/README.md +26 -2
- package/esm2020/lib/ng-http-caching-interceptor.service.mjs +3 -3
- package/esm2020/lib/ng-http-caching.module.mjs +4 -4
- package/esm2020/lib/ng-http-caching.service.mjs +10 -4
- package/esm2020/lib/storage/ng-http-caching-browser-storage.mjs +126 -0
- package/esm2020/lib/storage/ng-http-caching-local-storage.mjs +7 -0
- package/esm2020/lib/storage/ng-http-caching-session-storage.mjs +7 -0
- package/esm2020/public-api.mjs +4 -1
- package/fesm2015/ng-http-caching.mjs +155 -12
- package/fesm2015/ng-http-caching.mjs.map +1 -1
- package/fesm2020/ng-http-caching.mjs +155 -12
- package/fesm2020/ng-http-caching.mjs.map +1 -1
- package/lib/ng-http-caching.service.d.ts +10 -1
- package/lib/storage/ng-http-caching-browser-storage.d.ts +18 -0
- package/lib/storage/ng-http-caching-local-storage.d.ts +4 -0
- package/lib/storage/ng-http-caching-session-storage.d.ts +4 -0
- package/package.json +1 -1
- package/public-api.d.ts +3 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
1
|
+
import { HttpResponse, HTTP_INTERCEPTORS, HttpHeaders, HttpParams, HttpRequest } from '@angular/common/http';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
3
|
import { InjectionToken, Injectable, Inject, Optional, NgModule } from '@angular/core';
|
|
4
4
|
import { of } from 'rxjs';
|
|
@@ -54,6 +54,7 @@ var NgHttpCachingHeaders;
|
|
|
54
54
|
const NgHttpCachingConfigDefault = {
|
|
55
55
|
store: new NgHttpCachingMemoryStorage(),
|
|
56
56
|
lifetime: 60 * 60 * 100,
|
|
57
|
+
version: '1',
|
|
57
58
|
allowedMethod: ['GET'],
|
|
58
59
|
cacheStrategy: NgHttpCachingStrategy.ALLOW_ALL,
|
|
59
60
|
};
|
|
@@ -110,6 +111,7 @@ class NgHttpCachingService {
|
|
|
110
111
|
response: res,
|
|
111
112
|
request: req,
|
|
112
113
|
addedTime: Date.now(),
|
|
114
|
+
version: this.config.version,
|
|
113
115
|
};
|
|
114
116
|
if (this.isValid(entry)) {
|
|
115
117
|
(_a = this.config.store) === null || _a === void 0 ? void 0 : _a.set(key, entry);
|
|
@@ -208,6 +210,10 @@ class NgHttpCachingService {
|
|
|
208
210
|
return result;
|
|
209
211
|
}
|
|
210
212
|
}
|
|
213
|
+
// different version
|
|
214
|
+
if (this.config.version !== entry.version) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
211
217
|
return true;
|
|
212
218
|
}
|
|
213
219
|
/**
|
|
@@ -286,9 +292,9 @@ class NgHttpCachingService {
|
|
|
286
292
|
return this.queue.delete(key);
|
|
287
293
|
}
|
|
288
294
|
}
|
|
289
|
-
NgHttpCachingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0
|
|
290
|
-
NgHttpCachingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0
|
|
291
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0
|
|
295
|
+
NgHttpCachingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingService, deps: [{ token: NG_HTTP_CACHING_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
296
|
+
NgHttpCachingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingService });
|
|
297
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingService, decorators: [{
|
|
292
298
|
type: Injectable
|
|
293
299
|
}], ctorParameters: function () {
|
|
294
300
|
return [{ type: undefined, decorators: [{
|
|
@@ -352,9 +358,9 @@ class NgHttpCachingInterceptorService {
|
|
|
352
358
|
return next.handle(cloned);
|
|
353
359
|
}
|
|
354
360
|
}
|
|
355
|
-
NgHttpCachingInterceptorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0
|
|
356
|
-
NgHttpCachingInterceptorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0
|
|
357
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0
|
|
361
|
+
NgHttpCachingInterceptorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingInterceptorService, deps: [{ token: NgHttpCachingService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
362
|
+
NgHttpCachingInterceptorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingInterceptorService });
|
|
363
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingInterceptorService, decorators: [{
|
|
358
364
|
type: Injectable
|
|
359
365
|
}], ctorParameters: function () { return [{ type: NgHttpCachingService }]; } });
|
|
360
366
|
|
|
@@ -371,9 +377,9 @@ class NgHttpCachingModule {
|
|
|
371
377
|
};
|
|
372
378
|
}
|
|
373
379
|
}
|
|
374
|
-
NgHttpCachingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0
|
|
375
|
-
NgHttpCachingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0
|
|
376
|
-
NgHttpCachingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0
|
|
380
|
+
NgHttpCachingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
381
|
+
NgHttpCachingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingModule });
|
|
382
|
+
NgHttpCachingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingModule, providers: [
|
|
377
383
|
NgHttpCachingService,
|
|
378
384
|
{
|
|
379
385
|
provide: HTTP_INTERCEPTORS,
|
|
@@ -381,7 +387,7 @@ NgHttpCachingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ver
|
|
|
381
387
|
multi: true,
|
|
382
388
|
},
|
|
383
389
|
], imports: [[]] });
|
|
384
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0
|
|
390
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingModule, decorators: [{
|
|
385
391
|
type: NgModule,
|
|
386
392
|
args: [{
|
|
387
393
|
declarations: [],
|
|
@@ -398,6 +404,143 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImpor
|
|
|
398
404
|
}]
|
|
399
405
|
}] });
|
|
400
406
|
|
|
407
|
+
const KEY_PREFIX = 'NgHttpCaching::';
|
|
408
|
+
function serializeRequest(req) {
|
|
409
|
+
const request = req.clone(); // Make a clone, useful for doing destructive things
|
|
410
|
+
return JSON.stringify({
|
|
411
|
+
headers: Object.fromEntries(// Just a helper to make this into an object, not really required but makes the output nicer
|
|
412
|
+
request.headers.keys().map(// Get all of the headers
|
|
413
|
+
(key) => [key, request.headers.getAll(key)] // Get all of the corresponding values for the headers
|
|
414
|
+
)),
|
|
415
|
+
method: request.method,
|
|
416
|
+
url: request.url,
|
|
417
|
+
params: Object.fromEntries(// Just a helper to make this into an object, not really required but makes the output nicer
|
|
418
|
+
request.headers.keys().map(// Get all of the headers
|
|
419
|
+
(key) => [key, request.headers.getAll(key)] // Get all of the corresponding values for the headers
|
|
420
|
+
)),
|
|
421
|
+
withCredentials: request.withCredentials,
|
|
422
|
+
respnseType: request.responseType,
|
|
423
|
+
body: request.serializeBody() // Serialize the body, all well and good since we are working on a clone
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
function serializeResponse(res) {
|
|
427
|
+
const response = res.clone();
|
|
428
|
+
return JSON.stringify({
|
|
429
|
+
headers: Object.fromEntries(// Just a helper to make this into an object, not really required but makes the output nicer
|
|
430
|
+
response.headers.keys().map(// Get all of the headers
|
|
431
|
+
(key) => [key, response.headers.getAll(key)] // Get all of the corresponding values for the headers
|
|
432
|
+
)),
|
|
433
|
+
status: response.status,
|
|
434
|
+
statusText: response.statusText,
|
|
435
|
+
url: response.url,
|
|
436
|
+
body: response // Serialize the body, all well and good since we are working on a clone
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
function deserializeRequest(req) {
|
|
440
|
+
const request = JSON.parse(req);
|
|
441
|
+
const headers = new HttpHeaders(request.headers);
|
|
442
|
+
const params = new HttpParams(); // Probably some way to make this a one-liner, but alas, there are no good docs
|
|
443
|
+
// tslint:disable-next-line: forin
|
|
444
|
+
for (const parameter in request.params) {
|
|
445
|
+
request.params[parameter].forEach((paramValue) => params.append(parameter, paramValue));
|
|
446
|
+
}
|
|
447
|
+
return new HttpRequest(request.method, request.url, request.body, {
|
|
448
|
+
headers,
|
|
449
|
+
params,
|
|
450
|
+
responseType: request.responseType,
|
|
451
|
+
withCredentials: request.withCredentials
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
function deserializeResponse(res) {
|
|
455
|
+
const response = JSON.parse(res);
|
|
456
|
+
return new HttpResponse({
|
|
457
|
+
url: response.url,
|
|
458
|
+
headers: new HttpHeaders(response.headers),
|
|
459
|
+
body: response.body,
|
|
460
|
+
status: response.status,
|
|
461
|
+
statusText: response.statusText,
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
class NgHttpCachingBrowserStorage {
|
|
465
|
+
// eslint-disable-next-line no-unused-vars
|
|
466
|
+
constructor(storage) {
|
|
467
|
+
this.storage = storage;
|
|
468
|
+
}
|
|
469
|
+
get size() {
|
|
470
|
+
let count = 0;
|
|
471
|
+
for (let i = 0, e = this.storage.length; i < e; i++) {
|
|
472
|
+
const key = this.storage.key(i);
|
|
473
|
+
if (key && key.startsWith(KEY_PREFIX)) {
|
|
474
|
+
count++;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return count;
|
|
478
|
+
}
|
|
479
|
+
clear() {
|
|
480
|
+
for (let i = 0, e = this.storage.length; i < e; i++) {
|
|
481
|
+
const key = this.storage.key(i);
|
|
482
|
+
if (key && key.startsWith(KEY_PREFIX)) {
|
|
483
|
+
this.storage.removeItem(key);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
delete(key) {
|
|
488
|
+
this.storage.removeItem(KEY_PREFIX + key);
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
491
|
+
// eslint-disable-next-line no-unused-vars
|
|
492
|
+
forEach(callbackfn) {
|
|
493
|
+
// iterate this.storage
|
|
494
|
+
const lenPrefix = KEY_PREFIX.length;
|
|
495
|
+
for (let i = 0, e = this.storage.length; i < e; i++) {
|
|
496
|
+
const key = this.storage.key(i);
|
|
497
|
+
if (key && key.startsWith(KEY_PREFIX)) {
|
|
498
|
+
const value = this.get(key.substring(lenPrefix));
|
|
499
|
+
if (value) {
|
|
500
|
+
callbackfn(value, key);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
get(key) {
|
|
506
|
+
const item = this.storage.getItem(KEY_PREFIX + key);
|
|
507
|
+
if (item) {
|
|
508
|
+
const parsedItem = JSON.parse(item);
|
|
509
|
+
return {
|
|
510
|
+
url: parsedItem.url,
|
|
511
|
+
response: deserializeResponse(parsedItem.response),
|
|
512
|
+
request: deserializeRequest(parsedItem.request),
|
|
513
|
+
addedTime: parsedItem.addedTime,
|
|
514
|
+
version: parsedItem.version
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
return undefined;
|
|
518
|
+
}
|
|
519
|
+
has(key) {
|
|
520
|
+
return this.storage.getItem(KEY_PREFIX + key) !== undefined;
|
|
521
|
+
}
|
|
522
|
+
set(key, value) {
|
|
523
|
+
this.storage.setItem(KEY_PREFIX + key, JSON.stringify({
|
|
524
|
+
url: value.url,
|
|
525
|
+
response: serializeResponse(value.response),
|
|
526
|
+
request: serializeRequest(value.request),
|
|
527
|
+
addedTime: value.addedTime
|
|
528
|
+
}));
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
class NgHttpCachingLocalStorage extends NgHttpCachingBrowserStorage {
|
|
533
|
+
constructor() {
|
|
534
|
+
super(localStorage);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
class NgHttpCachingSessionStorage extends NgHttpCachingBrowserStorage {
|
|
539
|
+
constructor() {
|
|
540
|
+
super(sessionStorage);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
401
544
|
/*
|
|
402
545
|
* Public API Surface of ng-http-caching
|
|
403
546
|
*/
|
|
@@ -406,5 +549,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImpor
|
|
|
406
549
|
* Generated bundle index. Do not edit.
|
|
407
550
|
*/
|
|
408
551
|
|
|
409
|
-
export { NG_HTTP_CACHING_CONFIG, NgHttpCachingConfigDefault, NgHttpCachingHeaders, NgHttpCachingInterceptorService, NgHttpCachingMemoryStorage, NgHttpCachingModule, NgHttpCachingService, NgHttpCachingStrategy };
|
|
552
|
+
export { NG_HTTP_CACHING_CONFIG, NgHttpCachingBrowserStorage, NgHttpCachingConfigDefault, NgHttpCachingHeaders, NgHttpCachingInterceptorService, NgHttpCachingLocalStorage, NgHttpCachingMemoryStorage, NgHttpCachingModule, NgHttpCachingService, NgHttpCachingSessionStorage, NgHttpCachingStrategy, deserializeRequest, deserializeResponse, serializeRequest, serializeResponse };
|
|
410
553
|
//# sourceMappingURL=ng-http-caching.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ng-http-caching.mjs","sources":["../../../projects/ng-http-caching/src/lib/storage/ng-http-caching-memory-storage.ts","../../../projects/ng-http-caching/src/lib/ng-http-caching.service.ts","../../../projects/ng-http-caching/src/lib/ng-http-caching-interceptor.service.ts","../../../projects/ng-http-caching/src/lib/ng-http-caching.module.ts","../../../projects/ng-http-caching/src/public-api.ts","../../../projects/ng-http-caching/src/ng-http-caching.ts"],"sourcesContent":["import { NgHttpCachingStorageInterface } from './ng-http-caching-storage.interface';\r\nimport { NgHttpCachingEntry } from '../ng-http-caching.service';\r\n\r\nexport class NgHttpCachingMemoryStorage implements NgHttpCachingStorageInterface {\r\n\r\n get size(): number {\r\n return this.store.size;\r\n }\r\n\r\n private store = new Map<string, NgHttpCachingEntry>();\r\n\r\n clear(): void {\r\n this.store.clear();\r\n }\r\n\r\n delete(key: string): boolean {\r\n return this.store.delete(key);\r\n }\r\n\r\n // eslint-disable-next-line no-unused-vars\r\n forEach(callbackfn: (value: NgHttpCachingEntry, key: string) => void): void {\r\n return this.store.forEach(callbackfn);\r\n }\r\n\r\n get(key: string): NgHttpCachingEntry | undefined {\r\n return this.store.get(key);\r\n }\r\n\r\n has(key: string): boolean {\r\n return this.store.has(key);\r\n }\r\n\r\n set(key: string, value: NgHttpCachingEntry): void {\r\n this.store.set(key, value);\r\n }\r\n}\r\n","import { Injectable, InjectionToken, Inject, Optional } from '@angular/core';\r\nimport { HttpRequest, HttpResponse, HttpEvent } from '@angular/common/http';\r\nimport { Observable } from 'rxjs/internal/Observable';\r\nimport { NgHttpCachingStorageInterface } from './storage/ng-http-caching-storage.interface';\r\nimport { NgHttpCachingMemoryStorage } from './storage/ng-http-caching-memory-storage';\r\n\r\nexport interface NgHttpCachingEntry {\r\n url: string;\r\n response: HttpResponse<any>;\r\n request: HttpRequest<any>;\r\n addedTime: number;\r\n}\r\n\r\nexport const NG_HTTP_CACHING_CONFIG = new InjectionToken<NgHttpCachingConfig>(\r\n 'ng-http-caching.config'\r\n);\r\n\r\nexport enum NgHttpCachingStrategy {\r\n // eslint-disable-next-line no-unused-vars\r\n ALLOW_ALL = 'ALLOW_ALL',\r\n // eslint-disable-next-line no-unused-vars\r\n DISALLOW_ALL = 'DISALLOW_ALL',\r\n}\r\n\r\nexport enum NgHttpCachingHeaders {\r\n // eslint-disable-next-line no-unused-vars\r\n ALLOW_CACHE = 'X-NG-HTTP-CACHING-ALLOW-CACHE',\r\n // eslint-disable-next-line no-unused-vars\r\n DISALLOW_CACHE = 'X-NG-HTTP-CACHING-DISALLOW-CACHE',\r\n // eslint-disable-next-line no-unused-vars\r\n LIFETIME = 'X-NG-HTTP-CACHING-LIFETIME',\r\n // eslint-disable-next-line no-unused-vars\r\n TAG = 'X-NG-HTTP-CACHING-TAG',\r\n}\r\nexport interface NgHttpCachingConfig {\r\n store?: NgHttpCachingStorageInterface;\r\n lifetime?: number;\r\n allowedMethod?: string[];\r\n cacheStrategy?: NgHttpCachingStrategy;\r\n // eslint-disable-next-line no-unused-vars\r\n isExpired?: (entry: NgHttpCachingEntry) => boolean | undefined;\r\n // eslint-disable-next-line no-unused-vars\r\n isCacheable?: (req: HttpRequest<any>) => boolean | undefined;\r\n // eslint-disable-next-line no-unused-vars\r\n getKey?: (req: HttpRequest<any>) => string | undefined;\r\n // eslint-disable-next-line no-unused-vars\r\n isValid?: (entry: NgHttpCachingEntry) => boolean | undefined;\r\n}\r\n\r\nexport const NgHttpCachingConfigDefault: NgHttpCachingConfig = {\r\n store: new NgHttpCachingMemoryStorage(),\r\n lifetime: 60 * 60 * 100,\r\n allowedMethod: ['GET'],\r\n cacheStrategy: NgHttpCachingStrategy.ALLOW_ALL,\r\n};\r\n\r\n@Injectable()\r\nexport class NgHttpCachingService {\r\n\r\n private queue = new Map<string, Observable<HttpEvent<any>>>();\r\n\r\n private config: NgHttpCachingConfig = NgHttpCachingConfigDefault;\r\n\r\n constructor(\r\n @Inject(NG_HTTP_CACHING_CONFIG) @Optional() config: NgHttpCachingConfig\r\n ) {\r\n if (config) {\r\n this.config = { ...NgHttpCachingConfigDefault, ...config };\r\n }\r\n }\r\n\r\n /**\r\n * Return the config\r\n */\r\n getConfig(): NgHttpCachingConfig {\r\n return this.config;\r\n }\r\n\r\n /**\r\n * Return the queue map\r\n */\r\n getQueue(): Map<string, Observable<HttpEvent<any>>> {\r\n return this.queue;\r\n }\r\n\r\n /**\r\n * Return the cache store\r\n */\r\n getStore(): NgHttpCachingStorageInterface {\r\n return this.config.store as NgHttpCachingStorageInterface;\r\n }\r\n\r\n /**\r\n * Return response from cache\r\n */\r\n getFromCache(req: HttpRequest<any>): HttpResponse<any> | undefined {\r\n const key: string = this.getKey(req);\r\n const cached: NgHttpCachingEntry | undefined = this.config.store?.get(key);\r\n\r\n if (!cached) {\r\n return undefined;\r\n }\r\n\r\n if (this.isExpired(cached)) {\r\n this.clearCacheByKey(key);\r\n return undefined;\r\n }\r\n\r\n return cached.response;\r\n }\r\n\r\n /**\r\n * Add response to cache\r\n */\r\n addToCache(req: HttpRequest<any>, res: HttpResponse<any>): boolean {\r\n const key: string = this.getKey(req);\r\n const entry: NgHttpCachingEntry = {\r\n url: req.urlWithParams,\r\n response: res,\r\n request: req,\r\n addedTime: Date.now(),\r\n };\r\n if (this.isValid(entry)) {\r\n this.config.store?.set(key, entry);\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Delete response from cache\r\n */\r\n deleteFromCache(req: HttpRequest<any>): boolean {\r\n const key: string = this.getKey(req);\r\n return this.clearCacheByKey(key);\r\n }\r\n\r\n /**\r\n * Clear the cache\r\n */\r\n clearCache(): void {\r\n this.config.store?.clear();\r\n }\r\n\r\n /**\r\n * Clear the cache by key\r\n */\r\n clearCacheByKey(key: string): boolean {\r\n return (this.config.store as NgHttpCachingStorageInterface).delete(key);\r\n }\r\n\r\n /**\r\n * Clear the cache by regex\r\n */\r\n clearCacheByRegex(regex: RegExp): void {\r\n (this.config.store as NgHttpCachingStorageInterface).forEach((entry: NgHttpCachingEntry, key: string) => {\r\n if (regex.test(key)) {\r\n this.clearCacheByKey(key);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Clear the cache by TAG\r\n */\r\n clearCacheByTag(tag: string): void {\r\n (this.config.store as NgHttpCachingStorageInterface).forEach((entry: NgHttpCachingEntry, key: string) => {\r\n const tagHeader = entry.request.headers.get(NgHttpCachingHeaders.TAG);\r\n if (tagHeader && tagHeader.split(',').includes(tag)) {\r\n this.clearCacheByKey(key);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Run garbage collector (delete expired cache entry)\r\n */\r\n runGc(): void {\r\n (this.config.store as NgHttpCachingStorageInterface).forEach((entry: NgHttpCachingEntry, key: string) => {\r\n if (this.isExpired(entry)) {\r\n this.clearCacheByKey(key);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Return true if cache entry is expired\r\n */\r\n isExpired(entry: NgHttpCachingEntry): boolean {\r\n // if user provide custom method, use it\r\n if (typeof this.config.isExpired === 'function') {\r\n const result = this.config.isExpired(entry);\r\n // if result is undefined, normal behaviour is provided\r\n if (typeof result !== 'undefined') {\r\n return result;\r\n }\r\n }\r\n // config/default lifetime\r\n let lifetime = this.config.lifetime;\r\n // request has own lifetime\r\n if (entry.request.headers.has(NgHttpCachingHeaders.LIFETIME)) {\r\n lifetime = +(entry.request.headers.get(NgHttpCachingHeaders.LIFETIME) || '');\r\n }\r\n // never expire if 0\r\n if (lifetime === 0) {\r\n return false;\r\n }\r\n // wrong lifetime\r\n if ((lifetime as number) < 0) {\r\n throw new Error('lifetime must be greater than or equal 0');\r\n }\r\n return entry.addedTime + (lifetime as number) < Date.now();\r\n }\r\n\r\n /**\r\n * Return true if cache entry is valid for store in the cache\r\n */\r\n isValid(entry: NgHttpCachingEntry): boolean {\r\n // if user provide custom method, use it\r\n if (typeof this.config.isValid === 'function') {\r\n const result = this.config.isValid(entry);\r\n // if result is undefined, normal behaviour is provided\r\n if (typeof result !== 'undefined') {\r\n return result;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Return true if the request is cacheable\r\n */\r\n isCacheable(req: HttpRequest<any>): boolean {\r\n // if user provide custom method, use it\r\n if (typeof this.config.isCacheable === 'function') {\r\n const result = this.config.isCacheable(req);\r\n // if result is undefined, normal behaviour is provided\r\n if (typeof result !== 'undefined') {\r\n return result;\r\n }\r\n }\r\n // request has disallow cache header\r\n if (req.headers.has(NgHttpCachingHeaders.DISALLOW_CACHE)) {\r\n return false;\r\n }\r\n // strategy is disallow all...\r\n if (this.config.cacheStrategy === NgHttpCachingStrategy.DISALLOW_ALL) {\r\n // request isn't allowed if come without allow header\r\n if (!req.headers.has(NgHttpCachingHeaders.ALLOW_CACHE)) {\r\n return false;\r\n }\r\n }\r\n // if allowed method is only ALL, allow all http methos\r\n if (this.config.allowedMethod) {\r\n if (this.config.allowedMethod.length === 1) {\r\n if (this.config.allowedMethod[0] === 'ALL') {\r\n return true;\r\n }\r\n }\r\n // request is allowed if method is in allowedMethod\r\n return this.config.allowedMethod.indexOf(req.method) !== -1;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Return the cache key\r\n */\r\n getKey(req: HttpRequest<any>): string {\r\n // if user provide custom method, use it\r\n if (typeof this.config.getKey === 'function') {\r\n const result = this.config.getKey(req);\r\n // if result is undefined, normal behaviour is provided\r\n if (typeof result !== 'undefined') {\r\n return result;\r\n }\r\n }\r\n // default key id is url with query parameters\r\n return req.urlWithParams;\r\n }\r\n\r\n /**\r\n * Return observable from cache\r\n */\r\n getFromQueue(req: HttpRequest<any>): Observable<HttpEvent<any>> | undefined {\r\n const key: string = this.getKey(req);\r\n const cached: Observable<HttpEvent<any>> | undefined = this.queue.get(key);\r\n\r\n if (!cached) {\r\n return undefined;\r\n }\r\n\r\n return cached;\r\n }\r\n\r\n /**\r\n * Add observable to cache\r\n */\r\n addToQueue(req: HttpRequest<any>, obs: Observable<HttpEvent<any>>): void {\r\n const key: string = this.getKey(req);\r\n this.queue.set(key, obs);\r\n }\r\n\r\n /**\r\n * Delete observable from cache\r\n */\r\n deleteFromQueue(req: HttpRequest<any>): boolean {\r\n const key: string = this.getKey(req);\r\n return this.queue.delete(key);\r\n }\r\n}\r\n","import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { Observable, of } from 'rxjs';\nimport { tap, finalize, share } from 'rxjs/operators';\nimport { NgHttpCachingService, NgHttpCachingHeaders } from './ng-http-caching.service';\n\n\n@Injectable()\nexport class NgHttpCachingInterceptorService implements HttpInterceptor {\n\n // eslint-disable-next-line no-unused-vars\n constructor(private readonly cacheService: NgHttpCachingService) {}\n\n intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n // run garbage collector\n this.cacheService.runGc();\n\n // Don't cache if it's not cacheable\n if ( !this.cacheService.isCacheable(req) ) {\n return this.sendRequest(req, next);\n }\n\n // Checked if there is pending response for this request\n const cachedObservable: Observable<HttpEvent<any>> | undefined = this.cacheService.getFromQueue(req);\n if ( cachedObservable ) {\n // console.log('cachedObservable', req);\n return cachedObservable;\n }\n\n // Checked if there is cached response for this request\n const cachedResponse: HttpResponse<any> | undefined = this.cacheService.getFromCache(req);\n if (cachedResponse) {\n // console.log('cachedResponse', req);\n return of(cachedResponse.clone());\n }\n\n // If the request of going through for first time\n // then let the request proceed and cache the response\n // console.log('sendRequest', req);\n const shared = this.sendRequest(req, next).pipe(\n tap(event => {\n if (event instanceof HttpResponse) {\n this.cacheService.addToCache(req, event.clone());\n }\n }),\n finalize(() => {\n // delete pending request\n this.cacheService.deleteFromQueue(req);\n }),\n share()\n );\n\n // add pending request to queue for cache parallell request\n this.cacheService.addToQueue(req, shared);\n\n return shared;\n }\n\n /**\n * Send http request (next handler)\n */\n sendRequest(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n let cloned: HttpRequest<any> = req.clone();\n // trim custom headers before send request\n Object.values(NgHttpCachingHeaders).forEach(ngHttpCachingHeaders => {\n if ( cloned.headers.has(ngHttpCachingHeaders) ) {\n cloned = cloned.clone({ headers: cloned.headers.delete(ngHttpCachingHeaders) });\n }\n });\n return next.handle(cloned);\n }\n}\n","import { NgModule, ModuleWithProviders } from '@angular/core';\r\nimport { HTTP_INTERCEPTORS } from '@angular/common/http';\r\nimport {\r\n NG_HTTP_CACHING_CONFIG,\r\n NgHttpCachingConfig,\r\n NgHttpCachingService,\r\n} from './ng-http-caching.service';\r\nimport { NgHttpCachingInterceptorService } from './ng-http-caching-interceptor.service';\r\n\r\n@NgModule({\r\n declarations: [],\r\n imports: [],\r\n providers: [\r\n NgHttpCachingService,\r\n {\r\n provide: HTTP_INTERCEPTORS,\r\n useClass: NgHttpCachingInterceptorService,\r\n multi: true,\r\n },\r\n ],\r\n exports: [],\r\n})\r\nexport class NgHttpCachingModule {\r\n static forRoot(\r\n ngHttpCachingConfig?: NgHttpCachingConfig\r\n ): ModuleWithProviders<NgHttpCachingModule> {\r\n return {\r\n ngModule: NgHttpCachingModule,\r\n providers: [\r\n {\r\n provide: NG_HTTP_CACHING_CONFIG,\r\n useValue: ngHttpCachingConfig,\r\n },\r\n ],\r\n };\r\n }\r\n}\r\n","/*\r\n * Public API Surface of ng-http-caching\r\n */\r\n\r\nexport * from './lib/ng-http-caching-interceptor.service';\r\nexport * from './lib/ng-http-caching.service';\r\nexport * from './lib/ng-http-caching.module';\r\nexport * from './lib/storage/ng-http-caching-storage.interface';\r\nexport * from './lib/storage/ng-http-caching-memory-storage';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;MAGa,0BAA0B;IAAvC;QAMY,UAAK,GAAG,IAAI,GAAG,EAA8B,CAAC;KA0BzD;IA9BG,IAAI,IAAI;QACJ,OAAO,IAAI,CAA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AmB,aAVnB;QACT,oBAAoB;QACpB;YACE,OAAO,EAAE,iBAAiB;YAC1B,QAAQ,EAAE,+BAA+B;YACzC,KAAK,EAAE,IAAI;SACZ;KACF,YARQ,EAAE;2FAWA,mBAAmB;kBAb/B,QAAQ;mBAAC;oBACR,YAAY,EAAE,EAAE;oBAChB,OAAO,EAAE,EAAE;oBACX,SAAS,EAAE;wBACT,oBAAoB;wBACpB;4BACE,OAAO,EAAE,iBAAiB;4BAC1B,QAAQ,EAAE,+BAA+B;4BACzC,KAAK,EAAE,IAAI;yBACZ;qBACF;oBACD,OAAO,EAAE,EAAE;iBACZ;;;ACrBD;;;;ACAA;;;;;;"}
|
|
1
|
+
{"version":3,"file":"ng-http-caching.mjs","sources":["../../../projects/ng-http-caching/src/lib/storage/ng-http-caching-memory-storage.ts","../../../projects/ng-http-caching/src/lib/ng-http-caching.service.ts","../../../projects/ng-http-caching/src/lib/ng-http-caching-interceptor.service.ts","../../../projects/ng-http-caching/src/lib/ng-http-caching.module.ts","../../../projects/ng-http-caching/src/lib/storage/ng-http-caching-browser-storage.ts","../../../projects/ng-http-caching/src/lib/storage/ng-http-caching-local-storage.ts","../../../projects/ng-http-caching/src/lib/storage/ng-http-caching-session-storage.ts","../../../projects/ng-http-caching/src/public-api.ts","../../../projects/ng-http-caching/src/ng-http-caching.ts"],"sourcesContent":["import { NgHttpCachingStorageInterface } from './ng-http-caching-storage.interface';\r\nimport { NgHttpCachingEntry } from '../ng-http-caching.service';\r\n\r\nexport class NgHttpCachingMemoryStorage implements NgHttpCachingStorageInterface {\r\n\r\n get size(): number {\r\n return this.store.size;\r\n }\r\n\r\n private store = new Map<string, NgHttpCachingEntry>();\r\n\r\n clear(): void {\r\n this.store.clear();\r\n }\r\n\r\n delete(key: string): boolean {\r\n return this.store.delete(key);\r\n }\r\n\r\n // eslint-disable-next-line no-unused-vars\r\n forEach(callbackfn: (value: NgHttpCachingEntry, key: string) => void): void {\r\n return this.store.forEach(callbackfn);\r\n }\r\n\r\n get(key: string): NgHttpCachingEntry | undefined {\r\n return this.store.get(key);\r\n }\r\n\r\n has(key: string): boolean {\r\n return this.store.has(key);\r\n }\r\n\r\n set(key: string, value: NgHttpCachingEntry): void {\r\n this.store.set(key, value);\r\n }\r\n}\r\n","import { Injectable, InjectionToken, Inject, Optional } from '@angular/core';\r\nimport { HttpRequest, HttpResponse, HttpEvent } from '@angular/common/http';\r\nimport { Observable } from 'rxjs/internal/Observable';\r\nimport { NgHttpCachingStorageInterface } from './storage/ng-http-caching-storage.interface';\r\nimport { NgHttpCachingMemoryStorage } from './storage/ng-http-caching-memory-storage';\r\n\r\nexport interface NgHttpCachingEntry {\r\n url: string;\r\n response: HttpResponse<any>;\r\n request: HttpRequest<any>;\r\n addedTime: number;\r\n version: string;\r\n}\r\n\r\nexport const NG_HTTP_CACHING_CONFIG = new InjectionToken<NgHttpCachingConfig>(\r\n 'ng-http-caching.config'\r\n);\r\n\r\nexport enum NgHttpCachingStrategy {\r\n // eslint-disable-next-line no-unused-vars\r\n ALLOW_ALL = 'ALLOW_ALL',\r\n // eslint-disable-next-line no-unused-vars\r\n DISALLOW_ALL = 'DISALLOW_ALL',\r\n}\r\n\r\nexport enum NgHttpCachingHeaders {\r\n // eslint-disable-next-line no-unused-vars\r\n ALLOW_CACHE = 'X-NG-HTTP-CACHING-ALLOW-CACHE',\r\n // eslint-disable-next-line no-unused-vars\r\n DISALLOW_CACHE = 'X-NG-HTTP-CACHING-DISALLOW-CACHE',\r\n // eslint-disable-next-line no-unused-vars\r\n LIFETIME = 'X-NG-HTTP-CACHING-LIFETIME',\r\n // eslint-disable-next-line no-unused-vars\r\n TAG = 'X-NG-HTTP-CACHING-TAG',\r\n}\r\nexport interface NgHttpCachingConfig {\r\n store?: NgHttpCachingStorageInterface;\r\n lifetime?: number;\r\n allowedMethod?: string[];\r\n cacheStrategy?: NgHttpCachingStrategy;\r\n version?: string;\r\n // eslint-disable-next-line no-unused-vars\r\n isExpired?: (entry: NgHttpCachingEntry) => boolean | undefined;\r\n // eslint-disable-next-line no-unused-vars\r\n isCacheable?: (req: HttpRequest<any>) => boolean | undefined;\r\n // eslint-disable-next-line no-unused-vars\r\n getKey?: (req: HttpRequest<any>) => string | undefined;\r\n // eslint-disable-next-line no-unused-vars\r\n isValid?: (entry: NgHttpCachingEntry) => boolean | undefined;\r\n}\r\n\r\nexport interface NgHttpCachingDefaultConfig extends NgHttpCachingConfig {\r\n store: NgHttpCachingStorageInterface;\r\n lifetime: number;\r\n allowedMethod: string[];\r\n cacheStrategy: NgHttpCachingStrategy;\r\n version: string;\r\n}\r\n\r\nexport const NgHttpCachingConfigDefault: NgHttpCachingDefaultConfig = {\r\n store: new NgHttpCachingMemoryStorage(),\r\n lifetime: 60 * 60 * 100,\r\n version: '1',\r\n allowedMethod: ['GET'],\r\n cacheStrategy: NgHttpCachingStrategy.ALLOW_ALL,\r\n};\r\n\r\n@Injectable()\r\nexport class NgHttpCachingService {\r\n\r\n private queue = new Map<string, Observable<HttpEvent<any>>>();\r\n\r\n private config: NgHttpCachingDefaultConfig = NgHttpCachingConfigDefault;\r\n\r\n constructor(\r\n @Inject(NG_HTTP_CACHING_CONFIG) @Optional() config: NgHttpCachingConfig\r\n ) {\r\n if (config) {\r\n this.config = { ...NgHttpCachingConfigDefault, ...config };\r\n }\r\n }\r\n\r\n /**\r\n * Return the config\r\n */\r\n getConfig(): NgHttpCachingConfig {\r\n return this.config;\r\n }\r\n\r\n /**\r\n * Return the queue map\r\n */\r\n getQueue(): Map<string, Observable<HttpEvent<any>>> {\r\n return this.queue;\r\n }\r\n\r\n /**\r\n * Return the cache store\r\n */\r\n getStore(): NgHttpCachingStorageInterface {\r\n return this.config.store as NgHttpCachingStorageInterface;\r\n }\r\n\r\n /**\r\n * Return response from cache\r\n */\r\n getFromCache(req: HttpRequest<any>): HttpResponse<any> | undefined {\r\n const key: string = this.getKey(req);\r\n const cached: NgHttpCachingEntry | undefined = this.config.store?.get(key);\r\n\r\n if (!cached) {\r\n return undefined;\r\n }\r\n\r\n if (this.isExpired(cached)) {\r\n this.clearCacheByKey(key);\r\n return undefined;\r\n }\r\n\r\n return cached.response;\r\n }\r\n\r\n /**\r\n * Add response to cache\r\n */\r\n addToCache(req: HttpRequest<any>, res: HttpResponse<any>): boolean {\r\n const key: string = this.getKey(req);\r\n const entry: NgHttpCachingEntry = {\r\n url: req.urlWithParams,\r\n response: res,\r\n request: req,\r\n addedTime: Date.now(),\r\n version: this.config.version,\r\n };\r\n if (this.isValid(entry)) {\r\n this.config.store?.set(key, entry);\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Delete response from cache\r\n */\r\n deleteFromCache(req: HttpRequest<any>): boolean {\r\n const key: string = this.getKey(req);\r\n return this.clearCacheByKey(key);\r\n }\r\n\r\n /**\r\n * Clear the cache\r\n */\r\n clearCache(): void {\r\n this.config.store?.clear();\r\n }\r\n\r\n /**\r\n * Clear the cache by key\r\n */\r\n clearCacheByKey(key: string): boolean {\r\n return (this.config.store as NgHttpCachingStorageInterface).delete(key);\r\n }\r\n\r\n /**\r\n * Clear the cache by regex\r\n */\r\n clearCacheByRegex(regex: RegExp): void {\r\n (this.config.store as NgHttpCachingStorageInterface).forEach((entry: NgHttpCachingEntry, key: string) => {\r\n if (regex.test(key)) {\r\n this.clearCacheByKey(key);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Clear the cache by TAG\r\n */\r\n clearCacheByTag(tag: string): void {\r\n (this.config.store as NgHttpCachingStorageInterface).forEach((entry: NgHttpCachingEntry, key: string) => {\r\n const tagHeader = entry.request.headers.get(NgHttpCachingHeaders.TAG);\r\n if (tagHeader && tagHeader.split(',').includes(tag)) {\r\n this.clearCacheByKey(key);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Run garbage collector (delete expired cache entry)\r\n */\r\n runGc(): void {\r\n (this.config.store as NgHttpCachingStorageInterface).forEach((entry: NgHttpCachingEntry, key: string) => {\r\n if (this.isExpired(entry)) {\r\n this.clearCacheByKey(key);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Return true if cache entry is expired\r\n */\r\n isExpired(entry: NgHttpCachingEntry): boolean {\r\n // if user provide custom method, use it\r\n if (typeof this.config.isExpired === 'function') {\r\n const result = this.config.isExpired(entry);\r\n // if result is undefined, normal behaviour is provided\r\n if (typeof result !== 'undefined') {\r\n return result;\r\n }\r\n }\r\n // config/default lifetime\r\n let lifetime = this.config.lifetime;\r\n // request has own lifetime\r\n if (entry.request.headers.has(NgHttpCachingHeaders.LIFETIME)) {\r\n lifetime = +(entry.request.headers.get(NgHttpCachingHeaders.LIFETIME) || '');\r\n }\r\n // never expire if 0\r\n if (lifetime === 0) {\r\n return false;\r\n }\r\n // wrong lifetime\r\n if ((lifetime as number) < 0) {\r\n throw new Error('lifetime must be greater than or equal 0');\r\n }\r\n return entry.addedTime + (lifetime as number) < Date.now();\r\n }\r\n\r\n /**\r\n * Return true if cache entry is valid for store in the cache\r\n */\r\n isValid(entry: NgHttpCachingEntry): boolean {\r\n // if user provide custom method, use it\r\n if (typeof this.config.isValid === 'function') {\r\n const result = this.config.isValid(entry);\r\n // if result is undefined, normal behaviour is provided\r\n if (typeof result !== 'undefined') {\r\n return result;\r\n }\r\n }\r\n // different version\r\n if (this.config.version !== entry.version) {\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Return true if the request is cacheable\r\n */\r\n isCacheable(req: HttpRequest<any>): boolean {\r\n // if user provide custom method, use it\r\n if (typeof this.config.isCacheable === 'function') {\r\n const result = this.config.isCacheable(req);\r\n // if result is undefined, normal behaviour is provided\r\n if (typeof result !== 'undefined') {\r\n return result;\r\n }\r\n }\r\n // request has disallow cache header\r\n if (req.headers.has(NgHttpCachingHeaders.DISALLOW_CACHE)) {\r\n return false;\r\n }\r\n // strategy is disallow all...\r\n if (this.config.cacheStrategy === NgHttpCachingStrategy.DISALLOW_ALL) {\r\n // request isn't allowed if come without allow header\r\n if (!req.headers.has(NgHttpCachingHeaders.ALLOW_CACHE)) {\r\n return false;\r\n }\r\n }\r\n // if allowed method is only ALL, allow all http methos\r\n if (this.config.allowedMethod) {\r\n if (this.config.allowedMethod.length === 1) {\r\n if (this.config.allowedMethod[0] === 'ALL') {\r\n return true;\r\n }\r\n }\r\n // request is allowed if method is in allowedMethod\r\n return this.config.allowedMethod.indexOf(req.method) !== -1;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Return the cache key\r\n */\r\n getKey(req: HttpRequest<any>): string {\r\n // if user provide custom method, use it\r\n if (typeof this.config.getKey === 'function') {\r\n const result = this.config.getKey(req);\r\n // if result is undefined, normal behaviour is provided\r\n if (typeof result !== 'undefined') {\r\n return result;\r\n }\r\n }\r\n // default key id is url with query parameters\r\n return req.urlWithParams;\r\n }\r\n\r\n /**\r\n * Return observable from cache\r\n */\r\n getFromQueue(req: HttpRequest<any>): Observable<HttpEvent<any>> | undefined {\r\n const key: string = this.getKey(req);\r\n const cached: Observable<HttpEvent<any>> | undefined = this.queue.get(key);\r\n\r\n if (!cached) {\r\n return undefined;\r\n }\r\n\r\n return cached;\r\n }\r\n\r\n /**\r\n * Add observable to cache\r\n */\r\n addToQueue(req: HttpRequest<any>, obs: Observable<HttpEvent<any>>): void {\r\n const key: string = this.getKey(req);\r\n this.queue.set(key, obs);\r\n }\r\n\r\n /**\r\n * Delete observable from cache\r\n */\r\n deleteFromQueue(req: HttpRequest<any>): boolean {\r\n const key: string = this.getKey(req);\r\n return this.queue.delete(key);\r\n }\r\n}\r\n","import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { Observable, of } from 'rxjs';\nimport { tap, finalize, share } from 'rxjs/operators';\nimport { NgHttpCachingService, NgHttpCachingHeaders } from './ng-http-caching.service';\n\n\n@Injectable()\nexport class NgHttpCachingInterceptorService implements HttpInterceptor {\n\n // eslint-disable-next-line no-unused-vars\n constructor(private readonly cacheService: NgHttpCachingService) {}\n\n intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n // run garbage collector\n this.cacheService.runGc();\n\n // Don't cache if it's not cacheable\n if ( !this.cacheService.isCacheable(req) ) {\n return this.sendRequest(req, next);\n }\n\n // Checked if there is pending response for this request\n const cachedObservable: Observable<HttpEvent<any>> | undefined = this.cacheService.getFromQueue(req);\n if ( cachedObservable ) {\n // console.log('cachedObservable', req);\n return cachedObservable;\n }\n\n // Checked if there is cached response for this request\n const cachedResponse: HttpResponse<any> | undefined = this.cacheService.getFromCache(req);\n if (cachedResponse) {\n // console.log('cachedResponse', req);\n return of(cachedResponse.clone());\n }\n\n // If the request of going through for first time\n // then let the request proceed and cache the response\n // console.log('sendRequest', req);\n const shared = this.sendRequest(req, next).pipe(\n tap(event => {\n if (event instanceof HttpResponse) {\n this.cacheService.addToCache(req, event.clone());\n }\n }),\n finalize(() => {\n // delete pending request\n this.cacheService.deleteFromQueue(req);\n }),\n share()\n );\n\n // add pending request to queue for cache parallell request\n this.cacheService.addToQueue(req, shared);\n\n return shared;\n }\n\n /**\n * Send http request (next handler)\n */\n sendRequest(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n let cloned: HttpRequest<any> = req.clone();\n // trim custom headers before send request\n Object.values(NgHttpCachingHeaders).forEach(ngHttpCachingHeaders => {\n if ( cloned.headers.has(ngHttpCachingHeaders) ) {\n cloned = cloned.clone({ headers: cloned.headers.delete(ngHttpCachingHeaders) });\n }\n });\n return next.handle(cloned);\n }\n}\n","import { NgModule, ModuleWithProviders } from '@angular/core';\r\nimport { HTTP_INTERCEPTORS } from '@angular/common/http';\r\nimport {\r\n NG_HTTP_CACHING_CONFIG,\r\n NgHttpCachingConfig,\r\n NgHttpCachingService,\r\n} from './ng-http-caching.service';\r\nimport { NgHttpCachingInterceptorService } from './ng-http-caching-interceptor.service';\r\n\r\n@NgModule({\r\n declarations: [],\r\n imports: [],\r\n providers: [\r\n NgHttpCachingService,\r\n {\r\n provide: HTTP_INTERCEPTORS,\r\n useClass: NgHttpCachingInterceptorService,\r\n multi: true,\r\n },\r\n ],\r\n exports: [],\r\n})\r\nexport class NgHttpCachingModule {\r\n static forRoot(\r\n ngHttpCachingConfig?: NgHttpCachingConfig\r\n ): ModuleWithProviders<NgHttpCachingModule> {\r\n return {\r\n ngModule: NgHttpCachingModule,\r\n providers: [\r\n {\r\n provide: NG_HTTP_CACHING_CONFIG,\r\n useValue: ngHttpCachingConfig,\r\n },\r\n ],\r\n };\r\n }\r\n}\r\n","import { NgHttpCachingStorageInterface } from './ng-http-caching-storage.interface';\r\nimport { NgHttpCachingEntry } from '../ng-http-caching.service';\r\nimport { HttpHeaders, HttpParams, HttpRequest, HttpResponse } from '@angular/common/http';\r\n\r\nconst KEY_PREFIX = 'NgHttpCaching::';\r\n\r\nexport function serializeRequest(req: HttpRequest<any>): string {\r\n const request = req.clone(); // Make a clone, useful for doing destructive things\r\n return JSON.stringify({\r\n headers: Object.fromEntries( // Just a helper to make this into an object, not really required but makes the output nicer\r\n request.headers.keys().map( // Get all of the headers\r\n (key: string) => [key, request.headers.getAll(key)] // Get all of the corresponding values for the headers\r\n )\r\n ),\r\n method: request.method, // The Request Method, e.g. GET, POST, DELETE\r\n url: request.url, // The URL\r\n params: Object.fromEntries( // Just a helper to make this into an object, not really required but makes the output nicer\r\n request.headers.keys().map( // Get all of the headers\r\n (key: string) => [key, request.headers.getAll(key)] // Get all of the corresponding values for the headers\r\n )\r\n ), // The request parameters\r\n withCredentials: request.withCredentials, // Whether credentials are being sent\r\n respnseType: request.responseType, // The response type\r\n body: request.serializeBody() // Serialize the body, all well and good since we are working on a clone\r\n });\r\n}\r\n\r\nexport function serializeResponse(res: HttpResponse<any>): string {\r\n const response = res.clone();\r\n return JSON.stringify({\r\n headers: Object.fromEntries( // Just a helper to make this into an object, not really required but makes the output nicer\r\n response.headers.keys().map( // Get all of the headers\r\n (key: string) => [key, response.headers.getAll(key)] // Get all of the corresponding values for the headers\r\n )\r\n ),\r\n status: response.status,\r\n statusText: response.statusText,\r\n url: response.url,\r\n body: response // Serialize the body, all well and good since we are working on a clone\r\n });\r\n}\r\n\r\nexport function deserializeRequest<T = any>(req: string): HttpRequest<T> {\r\n const request = JSON.parse(req);\r\n const headers = new HttpHeaders(request.headers);\r\n const params = new HttpParams(); // Probably some way to make this a one-liner, but alas, there are no good docs\r\n // tslint:disable-next-line: forin\r\n for (const parameter in request.params) {\r\n request.params[parameter].forEach((paramValue: string) => params.append(parameter, paramValue));\r\n }\r\n return new HttpRequest(request.method, request.url, request.body, {\r\n headers,\r\n params,\r\n responseType: request.responseType,\r\n withCredentials: request.withCredentials\r\n });\r\n}\r\n\r\nexport function deserializeResponse<T = any>(res: string): HttpResponse<T> {\r\n const response = JSON.parse(res);\r\n return new HttpResponse<T>({\r\n url: response.url,\r\n headers: new HttpHeaders(response.headers),\r\n body: response.body,\r\n status: response.status,\r\n statusText: response.statusText,\r\n });\r\n}\r\n\r\nexport class NgHttpCachingBrowserStorage implements NgHttpCachingStorageInterface {\r\n\r\n // eslint-disable-next-line no-unused-vars\r\n constructor(private storage: Storage){}\r\n\r\n get size(): number {\r\n let count = 0;\r\n for (let i = 0, e = this.storage.length; i < e; i++) {\r\n const key = this.storage.key(i);\r\n if (key && key.startsWith(KEY_PREFIX)) {\r\n count++;\r\n }\r\n }\r\n return count;\r\n }\r\n\r\n clear(): void {\r\n for (let i = 0, e = this.storage.length; i < e; i++) {\r\n const key = this.storage.key(i);\r\n if (key && key.startsWith(KEY_PREFIX)) {\r\n this.storage.removeItem(key);\r\n }\r\n }\r\n }\r\n\r\n delete(key: string): boolean {\r\n this.storage.removeItem(KEY_PREFIX + key);\r\n return true;\r\n }\r\n\r\n // eslint-disable-next-line no-unused-vars\r\n forEach(callbackfn: (value: NgHttpCachingEntry, key: string) => void): void {\r\n // iterate this.storage\r\n const lenPrefix = KEY_PREFIX.length;\r\n for (let i = 0, e = this.storage.length; i < e; i++) {\r\n const key = this.storage.key(i);\r\n if (key && key.startsWith(KEY_PREFIX)) {\r\n const value = this.get(key.substring(lenPrefix));\r\n if (value) {\r\n callbackfn(value, key);\r\n }\r\n }\r\n }\r\n }\r\n\r\n get(key: string): NgHttpCachingEntry | undefined {\r\n const item = this.storage.getItem(KEY_PREFIX + key);\r\n if (item) {\r\n const parsedItem: StorageEntry = JSON.parse(item);\r\n return {\r\n url: parsedItem.url,\r\n response: deserializeResponse(parsedItem.response),\r\n request: deserializeRequest(parsedItem.request),\r\n addedTime: parsedItem.addedTime,\r\n version: parsedItem.version\r\n };\r\n }\r\n return undefined;\r\n }\r\n\r\n has(key: string): boolean {\r\n return this.storage.getItem(KEY_PREFIX + key) !== undefined;\r\n }\r\n\r\n set(key: string, value: NgHttpCachingEntry): void {\r\n this.storage.setItem(KEY_PREFIX + key, JSON.stringify({\r\n url: value.url,\r\n response: serializeResponse(value.response),\r\n request: serializeRequest(value.request),\r\n addedTime: value.addedTime\r\n } as StorageEntry));\r\n }\r\n}\r\n\r\ninterface StorageEntry {\r\n url: string;\r\n response: string;\r\n request: string;\r\n addedTime: number;\r\n version: string;\r\n}\r\n","import { NgHttpCachingBrowserStorage } from './ng-http-caching-browser-storage';\r\n\r\nexport class NgHttpCachingLocalStorage extends NgHttpCachingBrowserStorage {\r\n\r\n constructor(){\r\n super(localStorage);\r\n }\r\n}\r\n","import { NgHttpCachingBrowserStorage } from './ng-http-caching-browser-storage';\r\n\r\nexport class NgHttpCachingSessionStorage extends NgHttpCachingBrowserStorage {\r\n\r\n constructor(){\r\n super(sessionStorage);\r\n }\r\n}\r\n","/*\r\n * Public API Surface of ng-http-caching\r\n */\r\n\r\nexport * from './lib/ng-http-caching-interceptor.service';\r\nexport * from './lib/ng-http-caching.service';\r\nexport * from './lib/ng-http-caching.module';\r\nexport * from './lib/storage/ng-http-caching-storage.interface';\r\nexport * from './lib/storage/ng-http-caching-memory-storage';\r\nexport * from './lib/storage/ng-http-caching-local-storage';\r\nexport * from './lib/storage/ng-http-caching-session-storage';\r\nexport * from './lib/storage/ng-http-caching-browser-storage';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;MAGa,0BAA0B;IAAvC;QAMY,UAAK,GAAG,IAAI,GAAG,EAA8B,CAAC;KA0BzD;IA9BG,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;KAC1B;IAID,KAAK;QACD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;KACtB;IAED,MAAM,CAAC,GAAW;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;KACjC;;IAGD,OAAO,CAAC,UAA4D;QAChE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;KACzC;IAED,GAAG,CAAC,GAAW;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAC9B;IAED,GAAG,CAAC,GAAW;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAC9B;IAED,GAAG,CAAC,GAAW,EAAE,KAAyB;QACtC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;KAC9B;;;MCpBQ,sBAAsB,GAAG,IAAI,cAAc,CACtD,wBAAwB,EACxB;IAEU;AAAZ,WAAY,qBAAqB;;IAE/B,gDAAuB,CAAA;;IAEvB,sDAA6B,CAAA;AAC/B,CAAC,EALW,qBAAqB,KAArB,qBAAqB,QAKhC;IAEW;AAAZ,WAAY,oBAAoB;;IAE9B,qEAA6C,CAAA;;IAE7C,2EAAmD,CAAA;;IAEnD,+DAAuC,CAAA;;IAEvC,qDAA6B,CAAA;AAC/B,CAAC,EATW,oBAAoB,KAApB,oBAAoB,QAS/B;MAyBY,0BAA0B,GAA+B;IACpE,KAAK,EAAE,IAAI,0BAA0B,EAAE;IACvC,QAAQ,EAAE,E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AE,UAAU,CAAC,SAAS;gBAC/B,OAAO,EAAE,UAAU,CAAC,OAAO;aAC9B,CAAC;SACL;QACD,OAAO,SAAS,CAAC;KACpB;IAED,GAAG,CAAC,GAAW;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,GAAG,GAAG,CAAC,KAAK,SAAS,CAAC;KAC/D;IAED,GAAG,CAAC,GAAW,EAAE,KAAyB;QACtC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,GAAG,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC;YAClD,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,QAAQ,EAAE,iBAAiB,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3C,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC;YACxC,SAAS,EAAE,KAAK,CAAC,SAAS;SACb,CAAC,CAAC,CAAC;KACvB;;;MC1IQ,kCAAkC,2BAA2B;IAEtE;QACI,KAAK,CAAC,YAAY,CAAC,CAAC;KACvB;;;MCJQ,oCAAoC,2BAA2B;IAExE;QACI,KAAK,CAAC,cAAc,CAAC,CAAC;KACzB;;;ACNL;;;;ACAA;;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
1
|
+
import { HttpResponse, HTTP_INTERCEPTORS, HttpHeaders, HttpParams, HttpRequest } from '@angular/common/http';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
3
|
import { InjectionToken, Injectable, Inject, Optional, NgModule } from '@angular/core';
|
|
4
4
|
import { of } from 'rxjs';
|
|
@@ -54,6 +54,7 @@ var NgHttpCachingHeaders;
|
|
|
54
54
|
const NgHttpCachingConfigDefault = {
|
|
55
55
|
store: new NgHttpCachingMemoryStorage(),
|
|
56
56
|
lifetime: 60 * 60 * 100,
|
|
57
|
+
version: '1',
|
|
57
58
|
allowedMethod: ['GET'],
|
|
58
59
|
cacheStrategy: NgHttpCachingStrategy.ALLOW_ALL,
|
|
59
60
|
};
|
|
@@ -108,6 +109,7 @@ class NgHttpCachingService {
|
|
|
108
109
|
response: res,
|
|
109
110
|
request: req,
|
|
110
111
|
addedTime: Date.now(),
|
|
112
|
+
version: this.config.version,
|
|
111
113
|
};
|
|
112
114
|
if (this.isValid(entry)) {
|
|
113
115
|
this.config.store?.set(key, entry);
|
|
@@ -205,6 +207,10 @@ class NgHttpCachingService {
|
|
|
205
207
|
return result;
|
|
206
208
|
}
|
|
207
209
|
}
|
|
210
|
+
// different version
|
|
211
|
+
if (this.config.version !== entry.version) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
208
214
|
return true;
|
|
209
215
|
}
|
|
210
216
|
/**
|
|
@@ -283,9 +289,9 @@ class NgHttpCachingService {
|
|
|
283
289
|
return this.queue.delete(key);
|
|
284
290
|
}
|
|
285
291
|
}
|
|
286
|
-
NgHttpCachingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0
|
|
287
|
-
NgHttpCachingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0
|
|
288
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0
|
|
292
|
+
NgHttpCachingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingService, deps: [{ token: NG_HTTP_CACHING_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
293
|
+
NgHttpCachingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingService });
|
|
294
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingService, decorators: [{
|
|
289
295
|
type: Injectable
|
|
290
296
|
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
291
297
|
type: Inject,
|
|
@@ -347,9 +353,9 @@ class NgHttpCachingInterceptorService {
|
|
|
347
353
|
return next.handle(cloned);
|
|
348
354
|
}
|
|
349
355
|
}
|
|
350
|
-
NgHttpCachingInterceptorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0
|
|
351
|
-
NgHttpCachingInterceptorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0
|
|
352
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0
|
|
356
|
+
NgHttpCachingInterceptorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingInterceptorService, deps: [{ token: NgHttpCachingService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
357
|
+
NgHttpCachingInterceptorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingInterceptorService });
|
|
358
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingInterceptorService, decorators: [{
|
|
353
359
|
type: Injectable
|
|
354
360
|
}], ctorParameters: function () { return [{ type: NgHttpCachingService }]; } });
|
|
355
361
|
|
|
@@ -366,9 +372,9 @@ class NgHttpCachingModule {
|
|
|
366
372
|
};
|
|
367
373
|
}
|
|
368
374
|
}
|
|
369
|
-
NgHttpCachingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0
|
|
370
|
-
NgHttpCachingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0
|
|
371
|
-
NgHttpCachingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0
|
|
375
|
+
NgHttpCachingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
376
|
+
NgHttpCachingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingModule });
|
|
377
|
+
NgHttpCachingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingModule, providers: [
|
|
372
378
|
NgHttpCachingService,
|
|
373
379
|
{
|
|
374
380
|
provide: HTTP_INTERCEPTORS,
|
|
@@ -376,7 +382,7 @@ NgHttpCachingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ver
|
|
|
376
382
|
multi: true,
|
|
377
383
|
},
|
|
378
384
|
], imports: [[]] });
|
|
379
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0
|
|
385
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NgHttpCachingModule, decorators: [{
|
|
380
386
|
type: NgModule,
|
|
381
387
|
args: [{
|
|
382
388
|
declarations: [],
|
|
@@ -393,6 +399,143 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImpor
|
|
|
393
399
|
}]
|
|
394
400
|
}] });
|
|
395
401
|
|
|
402
|
+
const KEY_PREFIX = 'NgHttpCaching::';
|
|
403
|
+
function serializeRequest(req) {
|
|
404
|
+
const request = req.clone(); // Make a clone, useful for doing destructive things
|
|
405
|
+
return JSON.stringify({
|
|
406
|
+
headers: Object.fromEntries(// Just a helper to make this into an object, not really required but makes the output nicer
|
|
407
|
+
request.headers.keys().map(// Get all of the headers
|
|
408
|
+
(key) => [key, request.headers.getAll(key)] // Get all of the corresponding values for the headers
|
|
409
|
+
)),
|
|
410
|
+
method: request.method,
|
|
411
|
+
url: request.url,
|
|
412
|
+
params: Object.fromEntries(// Just a helper to make this into an object, not really required but makes the output nicer
|
|
413
|
+
request.headers.keys().map(// Get all of the headers
|
|
414
|
+
(key) => [key, request.headers.getAll(key)] // Get all of the corresponding values for the headers
|
|
415
|
+
)),
|
|
416
|
+
withCredentials: request.withCredentials,
|
|
417
|
+
respnseType: request.responseType,
|
|
418
|
+
body: request.serializeBody() // Serialize the body, all well and good since we are working on a clone
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
function serializeResponse(res) {
|
|
422
|
+
const response = res.clone();
|
|
423
|
+
return JSON.stringify({
|
|
424
|
+
headers: Object.fromEntries(// Just a helper to make this into an object, not really required but makes the output nicer
|
|
425
|
+
response.headers.keys().map(// Get all of the headers
|
|
426
|
+
(key) => [key, response.headers.getAll(key)] // Get all of the corresponding values for the headers
|
|
427
|
+
)),
|
|
428
|
+
status: response.status,
|
|
429
|
+
statusText: response.statusText,
|
|
430
|
+
url: response.url,
|
|
431
|
+
body: response // Serialize the body, all well and good since we are working on a clone
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
function deserializeRequest(req) {
|
|
435
|
+
const request = JSON.parse(req);
|
|
436
|
+
const headers = new HttpHeaders(request.headers);
|
|
437
|
+
const params = new HttpParams(); // Probably some way to make this a one-liner, but alas, there are no good docs
|
|
438
|
+
// tslint:disable-next-line: forin
|
|
439
|
+
for (const parameter in request.params) {
|
|
440
|
+
request.params[parameter].forEach((paramValue) => params.append(parameter, paramValue));
|
|
441
|
+
}
|
|
442
|
+
return new HttpRequest(request.method, request.url, request.body, {
|
|
443
|
+
headers,
|
|
444
|
+
params,
|
|
445
|
+
responseType: request.responseType,
|
|
446
|
+
withCredentials: request.withCredentials
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
function deserializeResponse(res) {
|
|
450
|
+
const response = JSON.parse(res);
|
|
451
|
+
return new HttpResponse({
|
|
452
|
+
url: response.url,
|
|
453
|
+
headers: new HttpHeaders(response.headers),
|
|
454
|
+
body: response.body,
|
|
455
|
+
status: response.status,
|
|
456
|
+
statusText: response.statusText,
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
class NgHttpCachingBrowserStorage {
|
|
460
|
+
// eslint-disable-next-line no-unused-vars
|
|
461
|
+
constructor(storage) {
|
|
462
|
+
this.storage = storage;
|
|
463
|
+
}
|
|
464
|
+
get size() {
|
|
465
|
+
let count = 0;
|
|
466
|
+
for (let i = 0, e = this.storage.length; i < e; i++) {
|
|
467
|
+
const key = this.storage.key(i);
|
|
468
|
+
if (key && key.startsWith(KEY_PREFIX)) {
|
|
469
|
+
count++;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return count;
|
|
473
|
+
}
|
|
474
|
+
clear() {
|
|
475
|
+
for (let i = 0, e = this.storage.length; i < e; i++) {
|
|
476
|
+
const key = this.storage.key(i);
|
|
477
|
+
if (key && key.startsWith(KEY_PREFIX)) {
|
|
478
|
+
this.storage.removeItem(key);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
delete(key) {
|
|
483
|
+
this.storage.removeItem(KEY_PREFIX + key);
|
|
484
|
+
return true;
|
|
485
|
+
}
|
|
486
|
+
// eslint-disable-next-line no-unused-vars
|
|
487
|
+
forEach(callbackfn) {
|
|
488
|
+
// iterate this.storage
|
|
489
|
+
const lenPrefix = KEY_PREFIX.length;
|
|
490
|
+
for (let i = 0, e = this.storage.length; i < e; i++) {
|
|
491
|
+
const key = this.storage.key(i);
|
|
492
|
+
if (key && key.startsWith(KEY_PREFIX)) {
|
|
493
|
+
const value = this.get(key.substring(lenPrefix));
|
|
494
|
+
if (value) {
|
|
495
|
+
callbackfn(value, key);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
get(key) {
|
|
501
|
+
const item = this.storage.getItem(KEY_PREFIX + key);
|
|
502
|
+
if (item) {
|
|
503
|
+
const parsedItem = JSON.parse(item);
|
|
504
|
+
return {
|
|
505
|
+
url: parsedItem.url,
|
|
506
|
+
response: deserializeResponse(parsedItem.response),
|
|
507
|
+
request: deserializeRequest(parsedItem.request),
|
|
508
|
+
addedTime: parsedItem.addedTime,
|
|
509
|
+
version: parsedItem.version
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
return undefined;
|
|
513
|
+
}
|
|
514
|
+
has(key) {
|
|
515
|
+
return this.storage.getItem(KEY_PREFIX + key) !== undefined;
|
|
516
|
+
}
|
|
517
|
+
set(key, value) {
|
|
518
|
+
this.storage.setItem(KEY_PREFIX + key, JSON.stringify({
|
|
519
|
+
url: value.url,
|
|
520
|
+
response: serializeResponse(value.response),
|
|
521
|
+
request: serializeRequest(value.request),
|
|
522
|
+
addedTime: value.addedTime
|
|
523
|
+
}));
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
class NgHttpCachingLocalStorage extends NgHttpCachingBrowserStorage {
|
|
528
|
+
constructor() {
|
|
529
|
+
super(localStorage);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
class NgHttpCachingSessionStorage extends NgHttpCachingBrowserStorage {
|
|
534
|
+
constructor() {
|
|
535
|
+
super(sessionStorage);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
396
539
|
/*
|
|
397
540
|
* Public API Surface of ng-http-caching
|
|
398
541
|
*/
|
|
@@ -401,5 +544,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImpor
|
|
|
401
544
|
* Generated bundle index. Do not edit.
|
|
402
545
|
*/
|
|
403
546
|
|
|
404
|
-
export { NG_HTTP_CACHING_CONFIG, NgHttpCachingConfigDefault, NgHttpCachingHeaders, NgHttpCachingInterceptorService, NgHttpCachingMemoryStorage, NgHttpCachingModule, NgHttpCachingService, NgHttpCachingStrategy };
|
|
547
|
+
export { NG_HTTP_CACHING_CONFIG, NgHttpCachingBrowserStorage, NgHttpCachingConfigDefault, NgHttpCachingHeaders, NgHttpCachingInterceptorService, NgHttpCachingLocalStorage, NgHttpCachingMemoryStorage, NgHttpCachingModule, NgHttpCachingService, NgHttpCachingSessionStorage, NgHttpCachingStrategy, deserializeRequest, deserializeResponse, serializeRequest, serializeResponse };
|
|
405
548
|
//# sourceMappingURL=ng-http-caching.mjs.map
|