@serwist/expiration 9.0.0-preview.11 → 9.0.0-preview.13
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/dist/CacheExpiration.d.ts +11 -14
- package/dist/CacheExpiration.d.ts.map +1 -1
- package/dist/ExpirationPlugin.d.ts +15 -20
- package/dist/ExpirationPlugin.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/CacheExpiration.ts +10 -15
- package/src/ExpirationPlugin.ts +15 -21
|
@@ -15,11 +15,10 @@ interface CacheExpirationConfig {
|
|
|
15
15
|
matchOptions?: CacheQueryOptions;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* [`Cache`](https://developer.mozilla.org/en-US/docs/Web/API/Cache).
|
|
18
|
+
* Allows you to expires cached responses based on age or maximum number of entries.
|
|
19
|
+
* @see https://serwist.pages.dev/docs/expiration/cache-expiration
|
|
21
20
|
*/
|
|
22
|
-
declare class CacheExpiration {
|
|
21
|
+
export declare class CacheExpiration {
|
|
23
22
|
private _isRunning;
|
|
24
23
|
private _rerunRequested;
|
|
25
24
|
private readonly _maxEntries?;
|
|
@@ -40,30 +39,28 @@ declare class CacheExpiration {
|
|
|
40
39
|
*/
|
|
41
40
|
expireEntries(): Promise<void>;
|
|
42
41
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* is accurate or when expiring, the timestamp is up-to-date.
|
|
42
|
+
* Updates the timestamp for the given URL, allowing it to be correctly
|
|
43
|
+
* tracked by the class.
|
|
46
44
|
*
|
|
47
45
|
* @param url
|
|
48
46
|
*/
|
|
49
47
|
updateTimestamp(url: string): Promise<void>;
|
|
50
48
|
/**
|
|
51
|
-
*
|
|
49
|
+
* Checks if a URL has expired or not before it's used.
|
|
52
50
|
*
|
|
53
|
-
* This
|
|
51
|
+
* This looks the timestamp up in IndexedDB and can be slow.
|
|
54
52
|
*
|
|
55
|
-
* Note: This method
|
|
56
|
-
* `expireEntries()` to remove
|
|
53
|
+
* Note: This method does not remove an expired entry, call
|
|
54
|
+
* `expireEntries()` to remove such entries instead.
|
|
57
55
|
*
|
|
58
56
|
* @param url
|
|
59
57
|
* @returns
|
|
60
58
|
*/
|
|
61
59
|
isURLExpired(url: string): Promise<boolean>;
|
|
62
60
|
/**
|
|
63
|
-
* Removes the IndexedDB
|
|
64
|
-
* metadata.
|
|
61
|
+
* Removes the IndexedDB used to keep track of cache expiration metadata.
|
|
65
62
|
*/
|
|
66
63
|
delete(): Promise<void>;
|
|
67
64
|
}
|
|
68
|
-
export {
|
|
65
|
+
export {};
|
|
69
66
|
//# sourceMappingURL=CacheExpiration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CacheExpiration.d.ts","sourceRoot":"","sources":["../src/CacheExpiration.ts"],"names":[],"mappings":"AAYA,UAAU,qBAAqB;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;CAClC;AAED
|
|
1
|
+
{"version":3,"file":"CacheExpiration.d.ts","sourceRoot":"","sources":["../src/CacheExpiration.ts"],"names":[],"mappings":"AAYA,UAAU,qBAAqB;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;CAClC;AAED;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAoB;IACnD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAuB;IAEvD;;;;;;OAMG;gBACS,SAAS,EAAE,MAAM,EAAE,MAAM,GAAE,qBAA0B;IA2CjE;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IA0CpC;;;;;OAKG;IACG,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAajD;;;;;;;;;;OAUG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAejD;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAM9B"}
|
|
@@ -15,32 +15,32 @@ export interface ExpirationPluginOptions {
|
|
|
15
15
|
*/
|
|
16
16
|
matchOptions?: CacheQueryOptions;
|
|
17
17
|
/**
|
|
18
|
-
* Whether to opt this cache
|
|
18
|
+
* Whether to opt this cache into automatic deletion if the available storage quota has been exceeded.
|
|
19
19
|
*/
|
|
20
20
|
purgeOnQuotaError?: boolean;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* This plugin can be used in a `@serwist/strategies` Strategy to regularly enforce a
|
|
24
|
-
* limit on the age and
|
|
24
|
+
* limit on the age and/or the number of cached requests.
|
|
25
25
|
*
|
|
26
|
-
* It can only be used with Strategy instances that have a
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* default runtime cache name.
|
|
26
|
+
* It can only be used with Strategy instances that have a custom `cacheName` property set.
|
|
27
|
+
* In other words, it can't be used to expire entries in strategies that use the default runtime
|
|
28
|
+
* cache name.
|
|
30
29
|
*
|
|
31
30
|
* Whenever a cached response is used or updated, this plugin will look
|
|
32
31
|
* at the associated cache and remove any old or extra responses.
|
|
33
32
|
*
|
|
34
33
|
* When using `maxAgeSeconds`, responses may be used *once* after expiring
|
|
35
34
|
* because the expiration clean up will not have occurred until *after* the
|
|
36
|
-
* cached response has been used. If the response has a "Date" header, then
|
|
37
|
-
*
|
|
38
|
-
* used immediately.
|
|
35
|
+
* cached response has been used. If the response has a "Date" header, then a lightweight expiration
|
|
36
|
+
* check is performed, and the response will not be used immediately.
|
|
39
37
|
*
|
|
40
|
-
* When using `maxEntries`, the
|
|
41
|
-
* from the cache
|
|
38
|
+
* When using `maxEntries`, the least recently requested entry will be removed
|
|
39
|
+
* from the cache.
|
|
40
|
+
*
|
|
41
|
+
* @see https://serwist.pages.dev/docs/expiration/expiration-plugin
|
|
42
42
|
*/
|
|
43
|
-
declare class ExpirationPlugin implements SerwistPlugin {
|
|
43
|
+
export declare class ExpirationPlugin implements SerwistPlugin {
|
|
44
44
|
private readonly _config;
|
|
45
45
|
private readonly _maxAgeSeconds?;
|
|
46
46
|
private _cacheExpirations;
|
|
@@ -95,16 +95,12 @@ declare class ExpirationPlugin implements SerwistPlugin {
|
|
|
95
95
|
*/
|
|
96
96
|
cacheDidUpdate: SerwistPlugin["cacheDidUpdate"];
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* - Deletes *all* the underlying Cache instances associated with this plugin
|
|
101
|
-
* instance, by calling caches.delete() on your behalf.
|
|
102
|
-
* - Deletes the metadata from IndexedDB used to keep track of expiration
|
|
103
|
-
* details for each Cache instance.
|
|
98
|
+
* Deletes the underlying `Cache` instance associated with this instance and the metadata
|
|
99
|
+
* from IndexedDB used to keep track of expiration details for each `Cache` instance.
|
|
104
100
|
*
|
|
105
101
|
* When using cache expiration, calling this method is preferable to calling
|
|
106
102
|
* `caches.delete()` directly, since this will ensure that the IndexedDB
|
|
107
|
-
* metadata is also cleanly removed and open IndexedDB instances are deleted.
|
|
103
|
+
* metadata is also cleanly removed and that open IndexedDB instances are deleted.
|
|
108
104
|
*
|
|
109
105
|
* Note that if you're *not* using cache expiration for a given cache, calling
|
|
110
106
|
* `caches.delete()` and passing in the cache's name should be sufficient.
|
|
@@ -112,5 +108,4 @@ declare class ExpirationPlugin implements SerwistPlugin {
|
|
|
112
108
|
*/
|
|
113
109
|
deleteCacheAndMetadata(): Promise<void>;
|
|
114
110
|
}
|
|
115
|
-
export { ExpirationPlugin };
|
|
116
111
|
//# sourceMappingURL=ExpirationPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpirationPlugin.d.ts","sourceRoot":"","sources":["../src/ExpirationPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAMnD,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,
|
|
1
|
+
{"version":3,"file":"ExpirationPlugin.d.ts","sourceRoot":"","sources":["../src/ExpirationPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAMnD,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,gBAAiB,YAAW,aAAa;IACpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0B;IAClD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAS;IACzC,OAAO,CAAC,iBAAiB,CAA+B;IAExD;;OAEG;gBACS,MAAM,GAAE,uBAA4B;IAsChD;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAa3B;;;;;;;;;;;;OAYG;IACH,wBAAwB,EAAE,aAAa,CAAC,0BAA0B,CAAC,CA+BjE;IAEF;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAqB5B;;;;;;;OAOG;IACH,OAAO,CAAC,uBAAuB;IAkB/B;;;;;;OAMG;IACH,cAAc,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAmB7C;IAEF;;;;;;;;;;;OAWG;IACG,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;CAW9C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/expiration",
|
|
3
|
-
"version": "9.0.0-preview.
|
|
3
|
+
"version": "9.0.0-preview.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A module that expires cached responses based on age or maximum number of entries.",
|
|
6
6
|
"files": [
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"idb": "8.0.0",
|
|
33
|
-
"@serwist/core": "9.0.0-preview.
|
|
33
|
+
"@serwist/core": "9.0.0-preview.13"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"rollup": "4.
|
|
37
|
-
"typescript": "5.
|
|
38
|
-
"@serwist/constants": "9.0.0-preview.
|
|
36
|
+
"rollup": "4.12.0",
|
|
37
|
+
"typescript": "5.5.0-dev.20240304",
|
|
38
|
+
"@serwist/constants": "9.0.0-preview.13"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"typescript": ">=5.0.0"
|
package/src/CacheExpiration.ts
CHANGED
|
@@ -28,11 +28,10 @@ interface CacheExpirationConfig {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* [`Cache`](https://developer.mozilla.org/en-US/docs/Web/API/Cache).
|
|
31
|
+
* Allows you to expires cached responses based on age or maximum number of entries.
|
|
32
|
+
* @see https://serwist.pages.dev/docs/expiration/cache-expiration
|
|
34
33
|
*/
|
|
35
|
-
class CacheExpiration {
|
|
34
|
+
export class CacheExpiration {
|
|
36
35
|
private _isRunning = false;
|
|
37
36
|
private _rerunRequested = false;
|
|
38
37
|
private readonly _maxEntries?: number;
|
|
@@ -137,9 +136,8 @@ class CacheExpiration {
|
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* is accurate or when expiring, the timestamp is up-to-date.
|
|
139
|
+
* Updates the timestamp for the given URL, allowing it to be correctly
|
|
140
|
+
* tracked by the class.
|
|
143
141
|
*
|
|
144
142
|
* @param url
|
|
145
143
|
*/
|
|
@@ -157,12 +155,12 @@ class CacheExpiration {
|
|
|
157
155
|
}
|
|
158
156
|
|
|
159
157
|
/**
|
|
160
|
-
*
|
|
158
|
+
* Checks if a URL has expired or not before it's used.
|
|
161
159
|
*
|
|
162
|
-
* This
|
|
160
|
+
* This looks the timestamp up in IndexedDB and can be slow.
|
|
163
161
|
*
|
|
164
|
-
* Note: This method
|
|
165
|
-
* `expireEntries()` to remove
|
|
162
|
+
* Note: This method does not remove an expired entry, call
|
|
163
|
+
* `expireEntries()` to remove such entries instead.
|
|
166
164
|
*
|
|
167
165
|
* @param url
|
|
168
166
|
* @returns
|
|
@@ -183,8 +181,7 @@ class CacheExpiration {
|
|
|
183
181
|
}
|
|
184
182
|
|
|
185
183
|
/**
|
|
186
|
-
* Removes the IndexedDB
|
|
187
|
-
* metadata.
|
|
184
|
+
* Removes the IndexedDB used to keep track of cache expiration metadata.
|
|
188
185
|
*/
|
|
189
186
|
async delete(): Promise<void> {
|
|
190
187
|
// Make sure we don't attempt another rerun if we're called in the middle of
|
|
@@ -193,5 +190,3 @@ class CacheExpiration {
|
|
|
193
190
|
await this._timestampModel.expireEntries(Infinity); // Expires all.
|
|
194
191
|
}
|
|
195
192
|
}
|
|
196
|
-
|
|
197
|
-
export { CacheExpiration };
|
package/src/ExpirationPlugin.ts
CHANGED
|
@@ -28,33 +28,33 @@ export interface ExpirationPluginOptions {
|
|
|
28
28
|
*/
|
|
29
29
|
matchOptions?: CacheQueryOptions;
|
|
30
30
|
/**
|
|
31
|
-
* Whether to opt this cache
|
|
31
|
+
* Whether to opt this cache into automatic deletion if the available storage quota has been exceeded.
|
|
32
32
|
*/
|
|
33
33
|
purgeOnQuotaError?: boolean;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* This plugin can be used in a `@serwist/strategies` Strategy to regularly enforce a
|
|
38
|
-
* limit on the age and
|
|
38
|
+
* limit on the age and/or the number of cached requests.
|
|
39
39
|
*
|
|
40
|
-
* It can only be used with Strategy instances that have a
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* default runtime cache name.
|
|
40
|
+
* It can only be used with Strategy instances that have a custom `cacheName` property set.
|
|
41
|
+
* In other words, it can't be used to expire entries in strategies that use the default runtime
|
|
42
|
+
* cache name.
|
|
44
43
|
*
|
|
45
44
|
* Whenever a cached response is used or updated, this plugin will look
|
|
46
45
|
* at the associated cache and remove any old or extra responses.
|
|
47
46
|
*
|
|
48
47
|
* When using `maxAgeSeconds`, responses may be used *once* after expiring
|
|
49
48
|
* because the expiration clean up will not have occurred until *after* the
|
|
50
|
-
* cached response has been used. If the response has a "Date" header, then
|
|
51
|
-
*
|
|
52
|
-
* used immediately.
|
|
49
|
+
* cached response has been used. If the response has a "Date" header, then a lightweight expiration
|
|
50
|
+
* check is performed, and the response will not be used immediately.
|
|
53
51
|
*
|
|
54
|
-
* When using `maxEntries`, the
|
|
55
|
-
* from the cache
|
|
52
|
+
* When using `maxEntries`, the least recently requested entry will be removed
|
|
53
|
+
* from the cache.
|
|
54
|
+
*
|
|
55
|
+
* @see https://serwist.pages.dev/docs/expiration/expiration-plugin
|
|
56
56
|
*/
|
|
57
|
-
class ExpirationPlugin implements SerwistPlugin {
|
|
57
|
+
export class ExpirationPlugin implements SerwistPlugin {
|
|
58
58
|
private readonly _config: ExpirationPluginOptions;
|
|
59
59
|
private readonly _maxAgeSeconds?: number;
|
|
60
60
|
private _cacheExpirations: Map<string, CacheExpiration>;
|
|
@@ -248,16 +248,12 @@ class ExpirationPlugin implements SerwistPlugin {
|
|
|
248
248
|
};
|
|
249
249
|
|
|
250
250
|
/**
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
* - Deletes *all* the underlying Cache instances associated with this plugin
|
|
254
|
-
* instance, by calling caches.delete() on your behalf.
|
|
255
|
-
* - Deletes the metadata from IndexedDB used to keep track of expiration
|
|
256
|
-
* details for each Cache instance.
|
|
251
|
+
* Deletes the underlying `Cache` instance associated with this instance and the metadata
|
|
252
|
+
* from IndexedDB used to keep track of expiration details for each `Cache` instance.
|
|
257
253
|
*
|
|
258
254
|
* When using cache expiration, calling this method is preferable to calling
|
|
259
255
|
* `caches.delete()` directly, since this will ensure that the IndexedDB
|
|
260
|
-
* metadata is also cleanly removed and open IndexedDB instances are deleted.
|
|
256
|
+
* metadata is also cleanly removed and that open IndexedDB instances are deleted.
|
|
261
257
|
*
|
|
262
258
|
* Note that if you're *not* using cache expiration for a given cache, calling
|
|
263
259
|
* `caches.delete()` and passing in the cache's name should be sufficient.
|
|
@@ -275,5 +271,3 @@ class ExpirationPlugin implements SerwistPlugin {
|
|
|
275
271
|
this._cacheExpirations = new Map();
|
|
276
272
|
}
|
|
277
273
|
}
|
|
278
|
-
|
|
279
|
-
export { ExpirationPlugin };
|