ng-http-caching 1.0.14 → 13.0.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.
Files changed (30) hide show
  1. package/README.md +31 -8
  2. package/esm2020/lib/ng-http-caching-interceptor.service.mjs +66 -0
  3. package/esm2020/lib/ng-http-caching.module.mjs +45 -0
  4. package/esm2020/lib/ng-http-caching.service.mjs +265 -0
  5. package/esm2020/lib/storage/ng-http-caching-local-storage.mjs +121 -0
  6. package/esm2020/lib/storage/ng-http-caching-memory-storage.mjs +28 -0
  7. package/esm2020/lib/storage/ng-http-caching-storage.interface.mjs +2 -0
  8. package/{esm2015/ng-http-caching.js → esm2020/ng-http-caching.mjs} +0 -0
  9. package/esm2020/public-api.mjs +10 -0
  10. package/fesm2015/ng-http-caching.mjs +530 -0
  11. package/fesm2015/ng-http-caching.mjs.map +1 -0
  12. package/{fesm2015/ng-http-caching.js → fesm2020/ng-http-caching.mjs} +181 -52
  13. package/fesm2020/ng-http-caching.mjs.map +1 -0
  14. package/lib/ng-http-caching-interceptor.service.d.ts +2 -2
  15. package/lib/ng-http-caching.module.d.ts +3 -2
  16. package/lib/ng-http-caching.service.d.ts +3 -3
  17. package/lib/storage/ng-http-caching-local-storage.d.ts +11 -0
  18. package/package.json +24 -14
  19. package/public-api.d.ts +1 -0
  20. package/bundles/ng-http-caching.umd.js +0 -430
  21. package/bundles/ng-http-caching.umd.js.map +0 -1
  22. package/bundles/ng-http-caching.umd.min.js +0 -2
  23. package/bundles/ng-http-caching.umd.min.js.map +0 -1
  24. package/esm2015/lib/ng-http-caching-interceptor.service.js +0 -65
  25. package/esm2015/lib/ng-http-caching.module.js +0 -44
  26. package/esm2015/lib/ng-http-caching.service.js +0 -260
  27. package/esm2015/lib/storage/ng-http-caching-memory-storage.js +0 -27
  28. package/esm2015/lib/storage/ng-http-caching-storage.interface.js +0 -1
  29. package/esm2015/public-api.js +0 -9
  30. package/fesm2015/ng-http-caching.js.map +0 -1
@@ -1,430 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common/http'), require('@angular/core'), require('rxjs'), require('rxjs/operators')) :
3
- typeof define === 'function' && define.amd ? define('ng-http-caching', ['exports', '@angular/common/http', '@angular/core', 'rxjs', 'rxjs/operators'], factory) :
4
- (global = global || self, factory(global['ng-http-caching'] = {}, global.ng.common.http, global.ng.core, global.rxjs, global.rxjs.operators));
5
- }(this, (function (exports, http, i0, rxjs, operators) { 'use strict';
6
-
7
- var NgHttpCachingMemoryStorage = /** @class */ (function () {
8
- function NgHttpCachingMemoryStorage() {
9
- this.store = new Map();
10
- }
11
- Object.defineProperty(NgHttpCachingMemoryStorage.prototype, "size", {
12
- get: function () {
13
- return this.store.size;
14
- },
15
- enumerable: false,
16
- configurable: true
17
- });
18
- NgHttpCachingMemoryStorage.prototype.clear = function () {
19
- this.store.clear();
20
- };
21
- NgHttpCachingMemoryStorage.prototype.delete = function (key) {
22
- return this.store.delete(key);
23
- };
24
- NgHttpCachingMemoryStorage.prototype.forEach = function (callbackfn) {
25
- return this.store.forEach(callbackfn);
26
- };
27
- NgHttpCachingMemoryStorage.prototype.get = function (key) {
28
- return this.store.get(key);
29
- };
30
- NgHttpCachingMemoryStorage.prototype.has = function (key) {
31
- return this.store.has(key);
32
- };
33
- NgHttpCachingMemoryStorage.prototype.set = function (key, value) {
34
- this.store.set(key, value);
35
- };
36
- return NgHttpCachingMemoryStorage;
37
- }());
38
-
39
- var NG_HTTP_CACHING_CONFIG = new i0.InjectionToken('ng-http-caching.config');
40
- (function (NgHttpCachingStrategy) {
41
- NgHttpCachingStrategy["ALLOW_ALL"] = "ALLOW_ALL";
42
- NgHttpCachingStrategy["DISALLOW_ALL"] = "DISALLOW_ALL";
43
- })(exports.NgHttpCachingStrategy || (exports.NgHttpCachingStrategy = {}));
44
- (function (NgHttpCachingHeaders) {
45
- NgHttpCachingHeaders["ALLOW_CACHE"] = "X-NG-HTTP-CACHING-ALLOW-CACHE";
46
- NgHttpCachingHeaders["DISALLOW_CACHE"] = "X-NG-HTTP-CACHING-DISALLOW-CACHE";
47
- NgHttpCachingHeaders["LIFETIME"] = "X-NG-HTTP-CACHING-LIFETIME";
48
- NgHttpCachingHeaders["TAG"] = "X-NG-HTTP-CACHING-TAG";
49
- })(exports.NgHttpCachingHeaders || (exports.NgHttpCachingHeaders = {}));
50
- var NgHttpCachingConfig = /** @class */ (function () {
51
- function NgHttpCachingConfig() {
52
- }
53
- return NgHttpCachingConfig;
54
- }());
55
- var NgHttpCachingConfigDefault = {
56
- store: new NgHttpCachingMemoryStorage(),
57
- lifetime: 60 * 60 * 100,
58
- allowedMethod: ['GET'],
59
- cacheStrategy: exports.NgHttpCachingStrategy.ALLOW_ALL,
60
- };
61
- var NgHttpCachingService = /** @class */ (function () {
62
- function NgHttpCachingService(config) {
63
- this.queue = new Map();
64
- if (config) {
65
- this.config = Object.assign(Object.assign({}, NgHttpCachingConfigDefault), config);
66
- }
67
- else {
68
- this.config = NgHttpCachingConfigDefault;
69
- }
70
- }
71
- /**
72
- * Return the config
73
- */
74
- NgHttpCachingService.prototype.getConfig = function () {
75
- return this.config;
76
- };
77
- /**
78
- * Return the queue map
79
- */
80
- NgHttpCachingService.prototype.getQueue = function () {
81
- return this.queue;
82
- };
83
- /**
84
- * Return the cache store
85
- */
86
- NgHttpCachingService.prototype.getStore = function () {
87
- return this.config.store;
88
- };
89
- /**
90
- * Return response from cache
91
- */
92
- NgHttpCachingService.prototype.getFromCache = function (req) {
93
- var key = this.getKey(req);
94
- var cached = this.config.store.get(key);
95
- if (!cached) {
96
- return undefined;
97
- }
98
- if (this.isExpired(cached)) {
99
- this.clearCacheByKey(key);
100
- return undefined;
101
- }
102
- return cached.response;
103
- };
104
- /**
105
- * Add response to cache
106
- */
107
- NgHttpCachingService.prototype.addToCache = function (req, res) {
108
- var key = this.getKey(req);
109
- var entry = {
110
- url: req.urlWithParams,
111
- response: res,
112
- request: req,
113
- addedTime: Date.now(),
114
- };
115
- if (this.isValid(entry)) {
116
- this.config.store.set(key, entry);
117
- return true;
118
- }
119
- return false;
120
- };
121
- /**
122
- * Delete response from cache
123
- */
124
- NgHttpCachingService.prototype.deleteFromCache = function (req) {
125
- var key = this.getKey(req);
126
- return this.clearCacheByKey(key);
127
- };
128
- /**
129
- * Clear the cache
130
- */
131
- NgHttpCachingService.prototype.clearCache = function () {
132
- this.config.store.clear();
133
- };
134
- /**
135
- * Clear the cache by key
136
- */
137
- NgHttpCachingService.prototype.clearCacheByKey = function (key) {
138
- return this.config.store.delete(key);
139
- };
140
- /**
141
- * Clear the cache by regex
142
- */
143
- NgHttpCachingService.prototype.clearCacheByRegex = function (regex) {
144
- var _this = this;
145
- this.config.store.forEach(function (entry, key) {
146
- if (regex.test(key)) {
147
- _this.clearCacheByKey(key);
148
- }
149
- });
150
- };
151
- /**
152
- * Clear the cache by TAG
153
- */
154
- NgHttpCachingService.prototype.clearCacheByTag = function (tag) {
155
- var _this = this;
156
- this.config.store.forEach(function (entry, key) {
157
- var tagHeader = entry.request.headers.get(exports.NgHttpCachingHeaders.TAG);
158
- if (tagHeader && tagHeader.split(',').includes(tag)) {
159
- _this.clearCacheByKey(key);
160
- }
161
- });
162
- };
163
- /**
164
- * Run garbage collector (delete expired cache entry)
165
- */
166
- NgHttpCachingService.prototype.runGc = function () {
167
- var _this = this;
168
- this.config.store.forEach(function (entry, key) {
169
- if (_this.isExpired(entry)) {
170
- _this.clearCacheByKey(key);
171
- }
172
- });
173
- };
174
- /**
175
- * Return true if cache entry is expired
176
- */
177
- NgHttpCachingService.prototype.isExpired = function (entry) {
178
- // if user provide custom method, use it
179
- if (typeof this.config.isExpired === 'function') {
180
- var result = this.config.isExpired(entry);
181
- // if result is undefined, normal behaviour is provided
182
- if (typeof result !== 'undefined') {
183
- return result;
184
- }
185
- }
186
- // config/default lifetime
187
- var lifetime = this.config.lifetime;
188
- // request has own lifetime
189
- if (entry.request.headers.has(exports.NgHttpCachingHeaders.LIFETIME)) {
190
- lifetime = +entry.request.headers.get(exports.NgHttpCachingHeaders.LIFETIME);
191
- }
192
- // never expire if 0
193
- if (lifetime === 0) {
194
- return false;
195
- }
196
- // wrong lifetime
197
- if (lifetime < 0) {
198
- throw new Error('lifetime must be greater than or equal 0');
199
- }
200
- return entry.addedTime + lifetime < Date.now();
201
- };
202
- /**
203
- * Return true if cache entry is valid for store in the cache
204
- */
205
- NgHttpCachingService.prototype.isValid = function (entry) {
206
- // if user provide custom method, use it
207
- if (typeof this.config.isValid === 'function') {
208
- var result = this.config.isValid(entry);
209
- // if result is undefined, normal behaviour is provided
210
- if (typeof result !== 'undefined') {
211
- return result;
212
- }
213
- }
214
- return true;
215
- };
216
- /**
217
- * Return true if the request is cacheable
218
- */
219
- NgHttpCachingService.prototype.isCacheable = function (req) {
220
- // if user provide custom method, use it
221
- if (typeof this.config.isCacheable === 'function') {
222
- var result = this.config.isCacheable(req);
223
- // if result is undefined, normal behaviour is provided
224
- if (typeof result !== 'undefined') {
225
- return result;
226
- }
227
- }
228
- // request has disallow cache header
229
- if (req.headers.has(exports.NgHttpCachingHeaders.DISALLOW_CACHE)) {
230
- return false;
231
- }
232
- // strategy is disallow all...
233
- if (this.config.cacheStrategy === exports.NgHttpCachingStrategy.DISALLOW_ALL) {
234
- // request isn't allowed if come without allow header
235
- if (!req.headers.has(exports.NgHttpCachingHeaders.ALLOW_CACHE)) {
236
- return false;
237
- }
238
- }
239
- // if allowed method is only ALL, allow all http methos
240
- if (this.config.allowedMethod.length === 1) {
241
- if (this.config.allowedMethod[0] === 'ALL') {
242
- return true;
243
- }
244
- }
245
- // request is allowed if method is in allowedMethod
246
- return this.config.allowedMethod.indexOf(req.method) !== -1;
247
- };
248
- /**
249
- * Return the cache key
250
- */
251
- NgHttpCachingService.prototype.getKey = function (req) {
252
- // if user provide custom method, use it
253
- if (typeof this.config.getKey === 'function') {
254
- var result = this.config.getKey(req);
255
- // if result is undefined, normal behaviour is provided
256
- if (typeof result !== 'undefined') {
257
- return result;
258
- }
259
- }
260
- // default key id is url with query parameters
261
- return req.urlWithParams;
262
- };
263
- /**
264
- * Return observable from cache
265
- */
266
- NgHttpCachingService.prototype.getFromQueue = function (req) {
267
- var key = this.getKey(req);
268
- var cached = this.queue.get(key);
269
- if (!cached) {
270
- return undefined;
271
- }
272
- return cached;
273
- };
274
- /**
275
- * Add observable to cache
276
- */
277
- NgHttpCachingService.prototype.addToQueue = function (req, obs) {
278
- var key = this.getKey(req);
279
- this.queue.set(key, obs);
280
- };
281
- /**
282
- * Delete observable from cache
283
- */
284
- NgHttpCachingService.prototype.deleteFromQueue = function (req) {
285
- var key = this.getKey(req);
286
- return this.queue.delete(key);
287
- };
288
- return NgHttpCachingService;
289
- }());
290
- NgHttpCachingService.ɵfac = function NgHttpCachingService_Factory(t) { return new (t || NgHttpCachingService)(i0.ɵɵinject(NG_HTTP_CACHING_CONFIG, 8)); };
291
- NgHttpCachingService.ɵprov = i0.ɵɵdefineInjectable({ token: NgHttpCachingService, factory: NgHttpCachingService.ɵfac });
292
- /*@__PURE__*/ (function () {
293
- i0.ɵsetClassMetadata(NgHttpCachingService, [{
294
- type: i0.Injectable
295
- }], function () {
296
- return [{ type: NgHttpCachingConfig, decorators: [{
297
- type: i0.Inject,
298
- args: [NG_HTTP_CACHING_CONFIG]
299
- }, {
300
- type: i0.Optional
301
- }] }];
302
- }, null);
303
- })();
304
-
305
- var NgHttpCachingInterceptorService = /** @class */ (function () {
306
- function NgHttpCachingInterceptorService(cacheService) {
307
- this.cacheService = cacheService;
308
- }
309
- NgHttpCachingInterceptorService.prototype.intercept = function (req, next) {
310
- var _this = this;
311
- // run garbage collector
312
- this.cacheService.runGc();
313
- // Don't cache if it's not cacheable
314
- if (!this.cacheService.isCacheable(req)) {
315
- return this.sendRequest(req, next);
316
- }
317
- // Checked if there is pending response for this request
318
- var cachedObservable = this.cacheService.getFromQueue(req);
319
- if (cachedObservable) {
320
- // console.log('cachedObservable', req);
321
- return cachedObservable;
322
- }
323
- // Checked if there is cached response for this request
324
- var cachedResponse = this.cacheService.getFromCache(req);
325
- if (cachedResponse) {
326
- // console.log('cachedResponse', req);
327
- return rxjs.of(cachedResponse.clone());
328
- }
329
- // If the request of going through for first time
330
- // then let the request proceed and cache the response
331
- // console.log('sendRequest', req);
332
- var shared = this.sendRequest(req, next).pipe(operators.tap(function (event) {
333
- if (event instanceof http.HttpResponse) {
334
- _this.cacheService.addToCache(req, event.clone());
335
- }
336
- }), operators.finalize(function () {
337
- // delete pending request
338
- _this.cacheService.deleteFromQueue(req);
339
- }), operators.share());
340
- // add pending request to queue for cache parallell request
341
- this.cacheService.addToQueue(req, shared);
342
- return shared;
343
- };
344
- /**
345
- * Send http request (next handler)
346
- */
347
- NgHttpCachingInterceptorService.prototype.sendRequest = function (req, next) {
348
- var cloned = req.clone();
349
- // trim custom headers before send request
350
- Object.values(exports.NgHttpCachingHeaders).forEach(function (ngHttpCachingHeaders) {
351
- if (cloned.headers.has(ngHttpCachingHeaders)) {
352
- cloned = cloned.clone({ headers: cloned.headers.delete(ngHttpCachingHeaders) });
353
- }
354
- });
355
- return next.handle(cloned);
356
- };
357
- return NgHttpCachingInterceptorService;
358
- }());
359
- NgHttpCachingInterceptorService.ɵfac = function NgHttpCachingInterceptorService_Factory(t) { return new (t || NgHttpCachingInterceptorService)(i0.ɵɵinject(NgHttpCachingService)); };
360
- NgHttpCachingInterceptorService.ɵprov = i0.ɵɵdefineInjectable({ token: NgHttpCachingInterceptorService, factory: NgHttpCachingInterceptorService.ɵfac });
361
- /*@__PURE__*/ (function () {
362
- i0.ɵsetClassMetadata(NgHttpCachingInterceptorService, [{
363
- type: i0.Injectable
364
- }], function () { return [{ type: NgHttpCachingService }]; }, null);
365
- })();
366
-
367
- var NgHttpCachingModule = /** @class */ (function () {
368
- function NgHttpCachingModule() {
369
- }
370
- NgHttpCachingModule.forRoot = function (ngHttpCachingConfig) {
371
- return {
372
- ngModule: NgHttpCachingModule,
373
- providers: [
374
- {
375
- provide: NG_HTTP_CACHING_CONFIG,
376
- useValue: ngHttpCachingConfig,
377
- },
378
- ],
379
- };
380
- };
381
- return NgHttpCachingModule;
382
- }());
383
- NgHttpCachingModule.ɵmod = i0.ɵɵdefineNgModule({ type: NgHttpCachingModule });
384
- NgHttpCachingModule.ɵinj = i0.ɵɵdefineInjector({ factory: function NgHttpCachingModule_Factory(t) { return new (t || NgHttpCachingModule)(); }, providers: [
385
- NgHttpCachingService,
386
- {
387
- provide: http.HTTP_INTERCEPTORS,
388
- useClass: NgHttpCachingInterceptorService,
389
- multi: true,
390
- },
391
- ], imports: [[]] });
392
- /*@__PURE__*/ (function () {
393
- i0.ɵsetClassMetadata(NgHttpCachingModule, [{
394
- type: i0.NgModule,
395
- args: [{
396
- declarations: [],
397
- imports: [],
398
- providers: [
399
- NgHttpCachingService,
400
- {
401
- provide: http.HTTP_INTERCEPTORS,
402
- useClass: NgHttpCachingInterceptorService,
403
- multi: true,
404
- },
405
- ],
406
- exports: [],
407
- }]
408
- }], null, null);
409
- })();
410
-
411
- /*
412
- * Public API Surface of ng-http-caching
413
- */
414
-
415
- /**
416
- * Generated bundle index. Do not edit.
417
- */
418
-
419
- exports.NG_HTTP_CACHING_CONFIG = NG_HTTP_CACHING_CONFIG;
420
- exports.NgHttpCachingConfig = NgHttpCachingConfig;
421
- exports.NgHttpCachingConfigDefault = NgHttpCachingConfigDefault;
422
- exports.NgHttpCachingInterceptorService = NgHttpCachingInterceptorService;
423
- exports.NgHttpCachingMemoryStorage = NgHttpCachingMemoryStorage;
424
- exports.NgHttpCachingModule = NgHttpCachingModule;
425
- exports.NgHttpCachingService = NgHttpCachingService;
426
-
427
- Object.defineProperty(exports, '__esModule', { value: true });
428
-
429
- })));
430
- //# sourceMappingURL=ng-http-caching.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ng-http-caching.umd.js","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 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 ALLOW_ALL = 'ALLOW_ALL',\r\n DISALLOW_ALL = 'DISALLOW_ALL',\r\n}\r\n\r\nexport enum NgHttpCachingHeaders {\r\n ALLOW_CACHE = 'X-NG-HTTP-CACHING-ALLOW-CACHE',\r\n DISALLOW_CACHE = 'X-NG-HTTP-CACHING-DISALLOW-CACHE',\r\n LIFETIME = 'X-NG-HTTP-CACHING-LIFETIME',\r\n TAG = 'X-NG-HTTP-CACHING-TAG',\r\n}\r\nexport class NgHttpCachingConfig {\r\n store?: NgHttpCachingStorageInterface;\r\n lifetime?: number;\r\n allowedMethod?: string[];\r\n cacheStrategy?: NgHttpCachingStrategy;\r\n isExpired?: (entry: NgHttpCachingEntry) => boolean | undefined;\r\n isCacheable?: (req: HttpRequest<any>) => boolean | undefined;\r\n getKey?: (req: HttpRequest<any>) => string | undefined;\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;\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 } else {\r\n this.config = NgHttpCachingConfigDefault;\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;\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 = 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.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.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.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.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 < 0) {\r\n throw new Error('lifetime must be greater than or equal 0');\r\n }\r\n return entry.addedTime + lifetime < 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.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\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>> = 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 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>> = 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> = 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';\nimport { HTTP_INTERCEPTORS } from '@angular/common/http';\nimport {\n NG_HTTP_CACHING_CONFIG,\n NgHttpCachingConfig,\n NgHttpCachingService,\n} from './ng-http-caching.service';\nimport { NgHttpCachingInterceptorService } from './ng-http-caching-interceptor.service';\n\n@NgModule({\n declarations: [],\n imports: [],\n providers: [\n NgHttpCachingService,\n {\n provide: HTTP_INTERCEPTORS,\n useClass: NgHttpCachingInterceptorService,\n multi: true,\n },\n ],\n exports: [],\n})\nexport class NgHttpCachingModule {\n static forRoot(\n ngHttpCachingConfig?: NgHttpCachingConfig\n ): ModuleWithProviders<NgHttpCachingModule> {\n return {\n ngModule: NgHttpCachingModule,\n providers: [\n {\n provide: NG_HTTP_CACHING_CONFIG,\n useValue: ngHttpCachingConfig,\n },\n ],\n };\n }\n}\n","/*\n * Public API Surface of ng-http-caching\n */\n\nexport * from './lib/ng-http-caching-interceptor.service';\nexport * from './lib/ng-http-caching.service';\nexport * from './lib/ng-http-caching.module';\nexport * from './lib/storage/ng-http-caching-storage.interface';\nexport * from './lib/storage/ng-http-caching-memory-storage';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["InjectionToken","NgHttpCachingStrategy","NgHttpCachingHeaders","Injectable","Inject","Optional","of","tap","HttpResponse","finalize","share","HTTP_INTERCEPTORS","NgModule"],"mappings":";;;;;;;QAGA;YAMY,UAAK,GAAG,IAAI,GAAG,EAA8B,CAAC;SAyBzD;QA7BG,sBAAI,4CAAI;iBAAR;gBACI,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;aAC1B;;;WAAA;QAID,0CAAK,GAAL;YACI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;SACtB;QAED,2CAAM,GAAN,UAAO,GAAW;YACd,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;SACjC;QAED,4CAAO,GAAP,UAAQ,UAA4D;YAChE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;SACzC;QAED,wCAAG,GAAH,UAAI,GAAW;YACX,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAC9B;QAED,wCAAG,GAAH,UAAI,GAAW;YACX,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAC9B;QAED,wCAAG,GAAH,UAAI,GAAW,EAAE,KAAyB;YACtC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;SAC9B;yCACJ;KAAA;;QCrBY,sBAAsB,GAAG,IAAIA,iBAA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;;;;;"}
@@ -1,2 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/common/http"),require("@angular/core"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("ng-http-caching",["exports","@angular/common/http","@angular/core","rxjs","rxjs/operators"],t):t((e=e||self)["ng-http-caching"]={},e.ng.common.http,e.ng.core,e.rxjs,e.rxjs.operators)}(this,(function(e,t,r,n,i){"use strict";var o,c,a=function(){function e(){this.store=new Map}return Object.defineProperty(e.prototype,"size",{get:function(){return this.store.size},enumerable:!1,configurable:!0}),e.prototype.clear=function(){this.store.clear()},e.prototype.delete=function(e){return this.store.delete(e)},e.prototype.forEach=function(e){return this.store.forEach(e)},e.prototype.get=function(e){return this.store.get(e)},e.prototype.has=function(e){return this.store.has(e)},e.prototype.set=function(e,t){this.store.set(e,t)},e}(),s=new r.InjectionToken("ng-http-caching.config");(o=e.NgHttpCachingStrategy||(e.NgHttpCachingStrategy={})).ALLOW_ALL="ALLOW_ALL",o.DISALLOW_ALL="DISALLOW_ALL",(c=e.NgHttpCachingHeaders||(e.NgHttpCachingHeaders={})).ALLOW_CACHE="X-NG-HTTP-CACHING-ALLOW-CACHE",c.DISALLOW_CACHE="X-NG-HTTP-CACHING-DISALLOW-CACHE",c.LIFETIME="X-NG-HTTP-CACHING-LIFETIME",c.TAG="X-NG-HTTP-CACHING-TAG";var u=function(){},h={store:new a,lifetime:36e4,allowedMethod:["GET"],cacheStrategy:e.NgHttpCachingStrategy.ALLOW_ALL},f=function(){function t(e){this.queue=new Map,this.config=e?Object.assign(Object.assign({},h),e):h}return t.prototype.getConfig=function(){return this.config},t.prototype.getQueue=function(){return this.queue},t.prototype.getStore=function(){return this.config.store},t.prototype.getFromCache=function(e){var t=this.getKey(e),r=this.config.store.get(t);if(r){if(!this.isExpired(r))return r.response;this.clearCacheByKey(t)}},t.prototype.addToCache=function(e,t){var r=this.getKey(e),n={url:e.urlWithParams,response:t,request:e,addedTime:Date.now()};return!!this.isValid(n)&&(this.config.store.set(r,n),!0)},t.prototype.deleteFromCache=function(e){var t=this.getKey(e);return this.clearCacheByKey(t)},t.prototype.clearCache=function(){this.config.store.clear()},t.prototype.clearCacheByKey=function(e){return this.config.store.delete(e)},t.prototype.clearCacheByRegex=function(e){var t=this;this.config.store.forEach((function(r,n){e.test(n)&&t.clearCacheByKey(n)}))},t.prototype.clearCacheByTag=function(t){var r=this;this.config.store.forEach((function(n,i){var o=n.request.headers.get(e.NgHttpCachingHeaders.TAG);o&&o.split(",").includes(t)&&r.clearCacheByKey(i)}))},t.prototype.runGc=function(){var e=this;this.config.store.forEach((function(t,r){e.isExpired(t)&&e.clearCacheByKey(r)}))},t.prototype.isExpired=function(t){if("function"==typeof this.config.isExpired){var r=this.config.isExpired(t);if(void 0!==r)return r}var n=this.config.lifetime;if(t.request.headers.has(e.NgHttpCachingHeaders.LIFETIME)&&(n=+t.request.headers.get(e.NgHttpCachingHeaders.LIFETIME)),0===n)return!1;if(n<0)throw new Error("lifetime must be greater than or equal 0");return t.addedTime+n<Date.now()},t.prototype.isValid=function(e){if("function"==typeof this.config.isValid){var t=this.config.isValid(e);if(void 0!==t)return t}return!0},t.prototype.isCacheable=function(t){if("function"==typeof this.config.isCacheable){var r=this.config.isCacheable(t);if(void 0!==r)return r}return!t.headers.has(e.NgHttpCachingHeaders.DISALLOW_CACHE)&&(!(this.config.cacheStrategy===e.NgHttpCachingStrategy.DISALLOW_ALL&&!t.headers.has(e.NgHttpCachingHeaders.ALLOW_CACHE))&&(1===this.config.allowedMethod.length&&"ALL"===this.config.allowedMethod[0]||-1!==this.config.allowedMethod.indexOf(t.method)))},t.prototype.getKey=function(e){if("function"==typeof this.config.getKey){var t=this.config.getKey(e);if(void 0!==t)return t}return e.urlWithParams},t.prototype.getFromQueue=function(e){var t=this.getKey(e),r=this.queue.get(t);if(r)return r},t.prototype.addToQueue=function(e,t){var r=this.getKey(e);this.queue.set(r,t)},t.prototype.deleteFromQueue=function(e){var t=this.getKey(e);return this.queue.delete(t)},t}();f.ɵfac=function(e){return new(e||f)(r.ɵɵinject(s,8))},f.ɵprov=r.ɵɵdefineInjectable({token:f,factory:f.ɵfac});var p=function(){function r(e){this.cacheService=e}return r.prototype.intercept=function(e,r){var o=this;if(this.cacheService.runGc(),!this.cacheService.isCacheable(e))return this.sendRequest(e,r);var c=this.cacheService.getFromQueue(e);if(c)return c;var a=this.cacheService.getFromCache(e);if(a)return n.of(a.clone());var s=this.sendRequest(e,r).pipe(i.tap((function(r){r instanceof t.HttpResponse&&o.cacheService.addToCache(e,r.clone())})),i.finalize((function(){o.cacheService.deleteFromQueue(e)})),i.share());return this.cacheService.addToQueue(e,s),s},r.prototype.sendRequest=function(t,r){var n=t.clone();return Object.values(e.NgHttpCachingHeaders).forEach((function(e){n.headers.has(e)&&(n=n.clone({headers:n.headers.delete(e)}))})),r.handle(n)},r}();p.ɵfac=function(e){return new(e||p)(r.ɵɵinject(f))},p.ɵprov=r.ɵɵdefineInjectable({token:p,factory:p.ɵfac});var g=function(){function e(){}return e.forRoot=function(t){return{ngModule:e,providers:[{provide:s,useValue:t}]}},e}();g.ɵmod=r.ɵɵdefineNgModule({type:g}),g.ɵinj=r.ɵɵdefineInjector({factory:function(e){return new(e||g)},providers:[f,{provide:t.HTTP_INTERCEPTORS,useClass:p,multi:!0}],imports:[[]]}),e.NG_HTTP_CACHING_CONFIG=s,e.NgHttpCachingConfig=u,e.NgHttpCachingConfigDefault=h,e.NgHttpCachingInterceptorService=p,e.NgHttpCachingMemoryStorage=a,e.NgHttpCachingModule=g,e.NgHttpCachingService=f,Object.defineProperty(e,"__esModule",{value:!0})}));
2
- //# sourceMappingURL=ng-http-caching.umd.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../projects/ng-http-caching/src/lib/ng-http-caching.service.ts","../../../projects/ng-http-caching/src/lib/storage/ng-http-caching-memory-storage.ts","../../../projects/ng-http-caching/src/lib/ng-http-caching-interceptor.service.ts","../../../projects/ng-http-caching/src/lib/ng-http-caching.module.ts"],"names":["NgHttpCachingStrategy","NgHttpCachingHeaders","NgHttpCachingMemoryStorage","this","store","Map","Object","defineProperty","prototype","size","clear","delete","key","forEach","callbackfn","get","has","set","value","NG_HTTP_CACHING_CONFIG","InjectionToken","NgHttpCachingConfigDefault","lifetime","allowedMethod","cacheStrategy","ALLOW_ALL","NgHttpCachingService","config","queue","assign","getConfig","getQueue","getStore","getFromCache","req","getKey","cached","isExpired","response","clearCacheByKey","addToCache","res","entry","url","urlWithParams","request","addedTime","Date","now","isValid","deleteFromCache","clearCache","clearCacheByRegex","regex","_this","test","clearCacheByTag","tag","tagHeader","headers","TAG","split","includes","runGc","result","LIFETIME","Error","isCacheable","DISALLOW_CACHE","DISALLOW_ALL","ALLOW_CACHE","length","indexOf","method","getFromQueue","addToQueue","obs","deleteFromQueue","i0","ɵɵinject","factory","ɵfac","NgHttpCachingInterceptorService","cacheService","intercept","next","sendRequest","cachedObservable","cachedResponse","of","clone","shared","pipe","tap","event","HttpResponse","finalize","share","cloned","values","ngHttpCachingHeaders","handle","NgHttpCachingModule","forRoot","ngHttpCachingConfig","ngModule","providers","provide","useValue","HTTP_INTERCEPTORS","useClass","multi","imports"],"mappings":"mcAiBYA,EAKAC,eCnBZ,SAAAC,IAMYC,KAAAC,MAAQ,IAAIC,WAJpBC,OAAAC,eAAIL,EAAAM,UAAA,OAAI,KAAR,WACI,OAAOL,KAAKC,MAAMK,sCAKtBP,EAAAM,UAAAE,MAAA,WACIP,KAAKC,MAAMM,SAGfR,EAAAM,UAAAG,OAAA,SAAOC,GACH,OAAOT,KAAKC,MAAMO,OAAOC,IAG7BV,EAAAM,UAAAK,QAAA,SAAQC,GACJ,OAAOX,KAAKC,MAAMS,QAAQC,IAG9BZ,EAAAM,UAAAO,IAAA,SAAIH,GACA,OAAOT,KAAKC,MAAMW,IAAIH,IAG1BV,EAAAM,UAAAQ,IAAA,SAAIJ,GACA,OAAOT,KAAKC,MAAMY,IAAIJ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ACEC,QAASxF,EACTyF,SAAUJ,2CATPF,iEAAAA,IAAmBI,UAVnB,CACThF,EACA,CACEiF,QAASE,EAAAA,kBACTC,SAAU5B,EACV6B,OAAO,IAEVC,QAAA,CARQ","sourcesContent":["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 ALLOW_ALL = 'ALLOW_ALL',\r\n DISALLOW_ALL = 'DISALLOW_ALL',\r\n}\r\n\r\nexport enum NgHttpCachingHeaders {\r\n ALLOW_CACHE = 'X-NG-HTTP-CACHING-ALLOW-CACHE',\r\n DISALLOW_CACHE = 'X-NG-HTTP-CACHING-DISALLOW-CACHE',\r\n LIFETIME = 'X-NG-HTTP-CACHING-LIFETIME',\r\n TAG = 'X-NG-HTTP-CACHING-TAG',\r\n}\r\nexport class NgHttpCachingConfig {\r\n store?: NgHttpCachingStorageInterface;\r\n lifetime?: number;\r\n allowedMethod?: string[];\r\n cacheStrategy?: NgHttpCachingStrategy;\r\n isExpired?: (entry: NgHttpCachingEntry) => boolean | undefined;\r\n isCacheable?: (req: HttpRequest<any>) => boolean | undefined;\r\n getKey?: (req: HttpRequest<any>) => string | undefined;\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;\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 } else {\r\n this.config = NgHttpCachingConfigDefault;\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;\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 = 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.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.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.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.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 < 0) {\r\n throw new Error('lifetime must be greater than or equal 0');\r\n }\r\n return entry.addedTime + lifetime < 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.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\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>> = 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 { 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 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 { 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 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>> = 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> = 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';\nimport { HTTP_INTERCEPTORS } from '@angular/common/http';\nimport {\n NG_HTTP_CACHING_CONFIG,\n NgHttpCachingConfig,\n NgHttpCachingService,\n} from './ng-http-caching.service';\nimport { NgHttpCachingInterceptorService } from './ng-http-caching-interceptor.service';\n\n@NgModule({\n declarations: [],\n imports: [],\n providers: [\n NgHttpCachingService,\n {\n provide: HTTP_INTERCEPTORS,\n useClass: NgHttpCachingInterceptorService,\n multi: true,\n },\n ],\n exports: [],\n})\nexport class NgHttpCachingModule {\n static forRoot(\n ngHttpCachingConfig?: NgHttpCachingConfig\n ): ModuleWithProviders<NgHttpCachingModule> {\n return {\n ngModule: NgHttpCachingModule,\n providers: [\n {\n provide: NG_HTTP_CACHING_CONFIG,\n useValue: ngHttpCachingConfig,\n },\n ],\n };\n }\n}\n"]}
@@ -1,65 +0,0 @@
1
- import { HttpResponse } from '@angular/common/http';
2
- import { Injectable } from '@angular/core';
3
- import { of } from 'rxjs';
4
- import { tap, finalize, share } from 'rxjs/operators';
5
- import { NgHttpCachingHeaders } from './ng-http-caching.service';
6
- import * as i0 from "@angular/core";
7
- import * as i1 from "./ng-http-caching.service";
8
- export class NgHttpCachingInterceptorService {
9
- constructor(cacheService) {
10
- this.cacheService = cacheService;
11
- }
12
- intercept(req, next) {
13
- // run garbage collector
14
- this.cacheService.runGc();
15
- // Don't cache if it's not cacheable
16
- if (!this.cacheService.isCacheable(req)) {
17
- return this.sendRequest(req, next);
18
- }
19
- // Checked if there is pending response for this request
20
- const cachedObservable = this.cacheService.getFromQueue(req);
21
- if (cachedObservable) {
22
- // console.log('cachedObservable', req);
23
- return cachedObservable;
24
- }
25
- // Checked if there is cached response for this request
26
- const cachedResponse = this.cacheService.getFromCache(req);
27
- if (cachedResponse) {
28
- // console.log('cachedResponse', req);
29
- return of(cachedResponse.clone());
30
- }
31
- // If the request of going through for first time
32
- // then let the request proceed and cache the response
33
- // console.log('sendRequest', req);
34
- const shared = this.sendRequest(req, next).pipe(tap(event => {
35
- if (event instanceof HttpResponse) {
36
- this.cacheService.addToCache(req, event.clone());
37
- }
38
- }), finalize(() => {
39
- // delete pending request
40
- this.cacheService.deleteFromQueue(req);
41
- }), share());
42
- // add pending request to queue for cache parallell request
43
- this.cacheService.addToQueue(req, shared);
44
- return shared;
45
- }
46
- /**
47
- * Send http request (next handler)
48
- */
49
- sendRequest(req, next) {
50
- let cloned = req.clone();
51
- // trim custom headers before send request
52
- Object.values(NgHttpCachingHeaders).forEach(ngHttpCachingHeaders => {
53
- if (cloned.headers.has(ngHttpCachingHeaders)) {
54
- cloned = cloned.clone({ headers: cloned.headers.delete(ngHttpCachingHeaders) });
55
- }
56
- });
57
- return next.handle(cloned);
58
- }
59
- }
60
- NgHttpCachingInterceptorService.ɵfac = function NgHttpCachingInterceptorService_Factory(t) { return new (t || NgHttpCachingInterceptorService)(i0.ɵɵinject(i1.NgHttpCachingService)); };
61
- NgHttpCachingInterceptorService.ɵprov = i0.ɵɵdefineInjectable({ token: NgHttpCachingInterceptorService, factory: NgHttpCachingInterceptorService.ɵfac });
62
- /*@__PURE__*/ (function () { i0.ɵsetClassMetadata(NgHttpCachingInterceptorService, [{
63
- type: Injectable
64
- }], function () { return [{ type: i1.NgHttpCachingService }]; }, null); })();
65
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmctaHR0cC1jYWNoaW5nLWludGVyY2VwdG9yLnNlcnZpY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9uZy1odHRwLWNhY2hpbmcvc3JjL2xpYi9uZy1odHRwLWNhY2hpbmctaW50ZXJjZXB0b3Iuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQXdELFlBQVksRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQzFHLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDM0MsT0FBTyxFQUFjLEVBQUUsRUFBRSxNQUFNLE1BQU0sQ0FBQztBQUN0QyxPQUFPLEVBQUUsR0FBRyxFQUFFLFFBQVEsRUFBRSxLQUFLLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQztBQUN0RCxPQUFPLEVBQXdCLG9CQUFvQixFQUFFLE1BQU0sMkJBQTJCLENBQUM7OztBQUl2RixNQUFNLE9BQU8sK0JBQStCO0lBRTFDLFlBQTZCLFlBQWtDO1FBQWxDLGlCQUFZLEdBQVosWUFBWSxDQUFzQjtJQUFHLENBQUM7SUFFbkUsU0FBUyxDQUFDLEdBQXFCLEVBQUUsSUFBaUI7UUFDaEQsd0JBQXdCO1FBQ3hCLEl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