ng-http-caching 15.0.3 → 15.2.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.
- package/README.md +1 -1
- package/esm2020/lib/ng-http-caching-interceptor.service.mjs +8 -9
- package/esm2020/lib/ng-http-caching.module.mjs +4 -4
- package/esm2020/lib/ng-http-caching.service.mjs +60 -13
- package/esm2020/lib/storage/ng-http-caching-browser-storage.mjs +10 -11
- package/esm2020/lib/storage/ng-http-caching-memory-storage.mjs +1 -1
- package/esm2020/lib/storage/ng-http-caching-storage.interface.mjs +1 -1
- package/fesm2015/ng-http-caching.mjs +79 -34
- package/fesm2015/ng-http-caching.mjs.map +1 -1
- package/fesm2020/ng-http-caching.mjs +79 -34
- package/fesm2020/ng-http-caching.mjs.map +1 -1
- package/lib/ng-http-caching.service.d.ts +92 -9
- package/lib/storage/ng-http-caching-browser-storage.d.ts +5 -5
- package/lib/storage/ng-http-caching-memory-storage.d.ts +1 -1
- package/lib/storage/ng-http-caching-storage.interface.d.ts +22 -1
- package/package.json +1 -1
|
@@ -4,21 +4,55 @@ import { Observable } from 'rxjs/internal/Observable';
|
|
|
4
4
|
import { NgHttpCachingStorageInterface } from './storage/ng-http-caching-storage.interface';
|
|
5
5
|
import * as i0 from "@angular/core";
|
|
6
6
|
export interface NgHttpCachingEntry<K = any, T = any> {
|
|
7
|
+
/**
|
|
8
|
+
* URL
|
|
9
|
+
*/
|
|
7
10
|
url: string;
|
|
11
|
+
/**
|
|
12
|
+
* HttpResponse
|
|
13
|
+
*/
|
|
8
14
|
response: HttpResponse<T>;
|
|
15
|
+
/**
|
|
16
|
+
* HttpRequest
|
|
17
|
+
*/
|
|
9
18
|
request: HttpRequest<K>;
|
|
19
|
+
/**
|
|
20
|
+
* Timestam of add to cache time
|
|
21
|
+
*/
|
|
10
22
|
addedTime: number;
|
|
23
|
+
/**
|
|
24
|
+
* Cache version
|
|
25
|
+
*/
|
|
11
26
|
version: string;
|
|
12
27
|
}
|
|
13
28
|
export declare const NG_HTTP_CACHING_CONFIG: InjectionToken<NgHttpCachingConfig>;
|
|
14
29
|
export declare enum NgHttpCachingStrategy {
|
|
30
|
+
/**
|
|
31
|
+
* All request are cacheable if HTTP method is into `allowedMethod`
|
|
32
|
+
*/
|
|
15
33
|
ALLOW_ALL = "ALLOW_ALL",
|
|
34
|
+
/**
|
|
35
|
+
* Only the request with `X-NG-HTTP-CACHING-ALLOW-CACHE` header are cacheable if HTTP method is into `allowedMethod`
|
|
36
|
+
*/
|
|
16
37
|
DISALLOW_ALL = "DISALLOW_ALL"
|
|
17
38
|
}
|
|
18
39
|
export declare enum NgHttpCachingHeaders {
|
|
40
|
+
/**
|
|
41
|
+
* Request is cacheable if HTTP method is into `allowedMethod`
|
|
42
|
+
*/
|
|
19
43
|
ALLOW_CACHE = "X-NG-HTTP-CACHING-ALLOW-CACHE",
|
|
44
|
+
/**
|
|
45
|
+
* Request isn't cacheable
|
|
46
|
+
*/
|
|
20
47
|
DISALLOW_CACHE = "X-NG-HTTP-CACHING-DISALLOW-CACHE",
|
|
48
|
+
/**
|
|
49
|
+
* Specific cache lifetime for the request
|
|
50
|
+
*/
|
|
21
51
|
LIFETIME = "X-NG-HTTP-CACHING-LIFETIME",
|
|
52
|
+
/**
|
|
53
|
+
* You can tag multiple request by adding this header with the same tag and
|
|
54
|
+
* using `NgHttpCachingService.clearCacheByTag(tag: string)` for delete all the tagged request
|
|
55
|
+
*/
|
|
22
56
|
TAG = "X-NG-HTTP-CACHING-TAG"
|
|
23
57
|
}
|
|
24
58
|
export declare const NgHttpCachingHeadersList: NgHttpCachingHeaders[];
|
|
@@ -30,14 +64,54 @@ export declare const NG_HTTP_CACHING_WEEK_IN_MS: number;
|
|
|
30
64
|
export declare const NG_HTTP_CACHING_MONTH_IN_MS: number;
|
|
31
65
|
export declare const NG_HTTP_CACHING_YEAR_IN_MS: number;
|
|
32
66
|
export interface NgHttpCachingConfig {
|
|
67
|
+
/**
|
|
68
|
+
* Set the cache store. You can implement your custom store by implement the `NgHttpCachingStorageInterface` interface, eg.:
|
|
69
|
+
*/
|
|
33
70
|
store?: NgHttpCachingStorageInterface;
|
|
71
|
+
/**
|
|
72
|
+
* Number of millisecond that a response is stored in the cache.
|
|
73
|
+
* You can set specific "lifetime" for each request by add the header `X-NG-HTTP-CACHING-LIFETIME` (see example below).
|
|
74
|
+
*/
|
|
34
75
|
lifetime?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Array of allowed HTTP methods to cache.
|
|
78
|
+
* You can allow multiple methods, eg.: `['GET', 'POST', 'PUT', 'DELETE', 'HEAD']` or
|
|
79
|
+
* allow all methods by: `['ALL']`. If `allowedMethod` is an empty array (`[]`), no response are cached.
|
|
80
|
+
* *Warning!* `NgHttpCaching` use the full url (url with query parameters) as unique key for the cached response,
|
|
81
|
+
* this is correct for the `GET` request but is _potentially_ wrong for other type of request (eg. `POST`, `PUT`).
|
|
82
|
+
* You can set a different "key" by customizing the `getKey` config method (see `getKey` section).
|
|
83
|
+
*/
|
|
35
84
|
allowedMethod?: string[];
|
|
85
|
+
/**
|
|
86
|
+
* Set the cache strategy, possible strategies are:
|
|
87
|
+
* - `NgHttpCachingStrategy.ALLOW_ALL`: All request are cacheable if HTTP method is into `allowedMethod`;
|
|
88
|
+
* - `NgHttpCachingStrategy.DISALLOW_ALL`: Only the request with `X-NG-HTTP-CACHING-ALLOW-CACHE` header are cacheable if HTTP method is into `allowedMethod`;
|
|
89
|
+
*/
|
|
36
90
|
cacheStrategy?: NgHttpCachingStrategy;
|
|
91
|
+
/**
|
|
92
|
+
* Cache version. When you have a breaking change, change the version, and it'll delete the current cache automatically.
|
|
93
|
+
* The default value is Angular major version (eg. 13), in this way, the cache is invalitaded on every Angular upgrade.
|
|
94
|
+
*/
|
|
37
95
|
version?: string;
|
|
96
|
+
/**
|
|
97
|
+
* If this function return `true` the request is expired and a new request is send to backend, if return `false` isn't expired.
|
|
98
|
+
* If the result is `undefined`, the normal behaviour is provided.
|
|
99
|
+
*/
|
|
38
100
|
isExpired?: <K, T>(entry: NgHttpCachingEntry<K, T>) => boolean | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* If this function return `true` the request is cacheable, if return `false` isn't cacheable.
|
|
103
|
+
* If the result is `undefined`, the normal behaviour is provided.
|
|
104
|
+
*/
|
|
39
105
|
isCacheable?: <K>(req: HttpRequest<K>) => boolean | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* This function return the unique key (`string`) for store the response into the cache.
|
|
108
|
+
* If the result is `undefined`, the normal behaviour is provided.
|
|
109
|
+
*/
|
|
40
110
|
getKey?: <K>(req: HttpRequest<K>) => string | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* If this function return `true` the cache entry is valid and can be strored, if return `false` isn't valid.
|
|
113
|
+
* If the result is `undefined`, the normal behaviour is provided.
|
|
114
|
+
*/
|
|
41
115
|
isValid?: <K, T>(entry: NgHttpCachingEntry<K, T>) => boolean | undefined;
|
|
42
116
|
}
|
|
43
117
|
export interface NgHttpCachingDefaultConfig extends NgHttpCachingConfig {
|
|
@@ -47,28 +121,29 @@ export interface NgHttpCachingDefaultConfig extends NgHttpCachingConfig {
|
|
|
47
121
|
cacheStrategy: NgHttpCachingStrategy;
|
|
48
122
|
version: string;
|
|
49
123
|
}
|
|
50
|
-
export declare const NgHttpCachingConfigDefault: NgHttpCachingDefaultConfig
|
|
124
|
+
export declare const NgHttpCachingConfigDefault: Readonly<NgHttpCachingDefaultConfig>;
|
|
51
125
|
export declare class NgHttpCachingService {
|
|
52
|
-
private queue;
|
|
53
|
-
private config;
|
|
126
|
+
private readonly queue;
|
|
127
|
+
private readonly config;
|
|
54
128
|
private gcLock;
|
|
55
|
-
|
|
129
|
+
private devMode;
|
|
130
|
+
constructor(config: Readonly<NgHttpCachingConfig>);
|
|
56
131
|
/**
|
|
57
132
|
* Return the config
|
|
58
133
|
*/
|
|
59
|
-
getConfig(): NgHttpCachingConfig
|
|
134
|
+
getConfig(): Readonly<NgHttpCachingConfig>;
|
|
60
135
|
/**
|
|
61
136
|
* Return the queue map
|
|
62
137
|
*/
|
|
63
|
-
getQueue(): Map<string, Observable<HttpEvent<any
|
|
138
|
+
getQueue(): Readonly<Map<string, Observable<HttpEvent<any>>>>;
|
|
64
139
|
/**
|
|
65
140
|
* Return the cache store
|
|
66
141
|
*/
|
|
67
|
-
getStore(): NgHttpCachingStorageInterface
|
|
142
|
+
getStore(): Readonly<NgHttpCachingStorageInterface>;
|
|
68
143
|
/**
|
|
69
144
|
* Return response from cache
|
|
70
145
|
*/
|
|
71
|
-
getFromCache<K, T>(req: HttpRequest<K>): HttpResponse<T
|
|
146
|
+
getFromCache<K, T>(req: HttpRequest<K>): Readonly<HttpResponse<T>> | undefined;
|
|
72
147
|
/**
|
|
73
148
|
* Add response to cache
|
|
74
149
|
*/
|
|
@@ -110,7 +185,9 @@ export declare class NgHttpCachingService {
|
|
|
110
185
|
*/
|
|
111
186
|
isCacheable<K>(req: HttpRequest<K>): boolean;
|
|
112
187
|
/**
|
|
113
|
-
* Return the cache key
|
|
188
|
+
* Return the cache key.
|
|
189
|
+
* Default key is http method plus url with query parameters, eg.:
|
|
190
|
+
* `GET@https://github.com/nigrosimone/ng-http-caching`
|
|
114
191
|
*/
|
|
115
192
|
getKey<K>(req: HttpRequest<K>): string;
|
|
116
193
|
/**
|
|
@@ -125,6 +202,12 @@ export declare class NgHttpCachingService {
|
|
|
125
202
|
* Delete observable from cache
|
|
126
203
|
*/
|
|
127
204
|
deleteFromQueue<K>(req: HttpRequest<K>): boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Recursively Object.freeze simple Javascript structures consisting of plain objects, arrays, and primitives.
|
|
207
|
+
* Make the data immutable.
|
|
208
|
+
* @returns immutable object
|
|
209
|
+
*/
|
|
210
|
+
private deepFreeze;
|
|
128
211
|
static ɵfac: i0.ɵɵFactoryDeclaration<NgHttpCachingService, [{ optional: true; }]>;
|
|
129
212
|
static ɵprov: i0.ɵɵInjectableDeclaration<NgHttpCachingService>;
|
|
130
213
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { NgHttpCachingStorageInterface } from './ng-http-caching-storage.interface';
|
|
2
2
|
import { NgHttpCachingEntry } from '../ng-http-caching.service';
|
|
3
3
|
import { HttpRequest, HttpResponse } from '@angular/common/http';
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
6
|
-
export declare
|
|
7
|
-
export declare
|
|
4
|
+
export declare const serializeRequest: (req: HttpRequest<any>) => string;
|
|
5
|
+
export declare const serializeResponse: (res: HttpResponse<any>) => string;
|
|
6
|
+
export declare const deserializeRequest: <T = any>(req: string) => HttpRequest<T>;
|
|
7
|
+
export declare const deserializeResponse: <T = any>(res: string) => HttpResponse<T>;
|
|
8
8
|
export declare class NgHttpCachingBrowserStorage implements NgHttpCachingStorageInterface {
|
|
9
9
|
private storage;
|
|
10
10
|
constructor(storage: Storage);
|
|
@@ -12,7 +12,7 @@ export declare class NgHttpCachingBrowserStorage implements NgHttpCachingStorage
|
|
|
12
12
|
clear(): void;
|
|
13
13
|
delete(key: string): boolean;
|
|
14
14
|
forEach(callbackfn: (value: NgHttpCachingEntry, key: string) => void): void;
|
|
15
|
-
get(key: string): NgHttpCachingEntry | undefined;
|
|
15
|
+
get(key: string): Readonly<NgHttpCachingEntry> | undefined;
|
|
16
16
|
has(key: string): boolean;
|
|
17
17
|
set(key: string, value: NgHttpCachingEntry): void;
|
|
18
18
|
}
|
|
@@ -6,7 +6,7 @@ export declare class NgHttpCachingMemoryStorage implements NgHttpCachingStorageI
|
|
|
6
6
|
clear(): void;
|
|
7
7
|
delete(key: string): boolean;
|
|
8
8
|
forEach<K, T>(callbackfn: (value: NgHttpCachingEntry<K, T>, key: string) => void): void;
|
|
9
|
-
get<K, T>(key: string): NgHttpCachingEntry<K, T
|
|
9
|
+
get<K, T>(key: string): Readonly<NgHttpCachingEntry<K, T>> | undefined;
|
|
10
10
|
has(key: string): boolean;
|
|
11
11
|
set<K, T>(key: string, value: NgHttpCachingEntry<K, T>): void;
|
|
12
12
|
}
|
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
import { NgHttpCachingEntry } from '../ng-http-caching.service';
|
|
2
2
|
export interface NgHttpCachingStorageInterface {
|
|
3
|
+
/**
|
|
4
|
+
* The number of cached entries.
|
|
5
|
+
*/
|
|
3
6
|
readonly size: number;
|
|
7
|
+
/**
|
|
8
|
+
* Clear the cache.
|
|
9
|
+
*/
|
|
4
10
|
clear(): void;
|
|
11
|
+
/**
|
|
12
|
+
* Delete the chache entry for the provided key.
|
|
13
|
+
*/
|
|
5
14
|
delete(key: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The forEach() method executes a provided function once for each chache entry.
|
|
17
|
+
*/
|
|
6
18
|
forEach<K = any, T = any>(callbackfn: (value: NgHttpCachingEntry<K, T>, key: string) => void): void;
|
|
7
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Return the chache entry for the provided key.
|
|
21
|
+
*/
|
|
22
|
+
get<K = any, T = any>(key: string): Readonly<NgHttpCachingEntry<K, T>> | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Return true if the cache entry exists the provided key.
|
|
25
|
+
*/
|
|
8
26
|
has(key: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Set the chache entry for the provided key.
|
|
29
|
+
*/
|
|
9
30
|
set<K = any, T = any>(key: string, value: NgHttpCachingEntry<K, T>): void;
|
|
10
31
|
}
|