@serwist/expiration 9.0.0-preview.15 → 9.0.0-preview.17
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/index.js
CHANGED
|
@@ -15,12 +15,12 @@ class CacheTimestampsModel {
|
|
|
15
15
|
constructor(cacheName){
|
|
16
16
|
this._cacheName = cacheName;
|
|
17
17
|
}
|
|
18
|
+
_getId(url) {
|
|
19
|
+
return `${this._cacheName}|${normalizeURL(url)}`;
|
|
20
|
+
}
|
|
18
21
|
_upgradeDb(db) {
|
|
19
22
|
const objStore = db.createObjectStore(CACHE_OBJECT_STORE, {
|
|
20
|
-
keyPath:
|
|
21
|
-
"url",
|
|
22
|
-
"cacheName"
|
|
23
|
-
]
|
|
23
|
+
keyPath: "id"
|
|
24
24
|
});
|
|
25
25
|
objStore.createIndex("cacheName", "cacheName", {
|
|
26
26
|
unique: false
|
|
@@ -38,6 +38,7 @@ class CacheTimestampsModel {
|
|
|
38
38
|
async setTimestamp(url, timestamp) {
|
|
39
39
|
url = normalizeURL(url);
|
|
40
40
|
const entry = {
|
|
41
|
+
id: this._getId(url),
|
|
41
42
|
cacheName: this._cacheName,
|
|
42
43
|
url,
|
|
43
44
|
timestamp
|
|
@@ -51,10 +52,7 @@ class CacheTimestampsModel {
|
|
|
51
52
|
}
|
|
52
53
|
async getTimestamp(url) {
|
|
53
54
|
const db = await this.getDb();
|
|
54
|
-
const entry = await db.get(CACHE_OBJECT_STORE,
|
|
55
|
-
this._cacheName,
|
|
56
|
-
normalizeURL(url)
|
|
57
|
-
]);
|
|
55
|
+
const entry = await db.get(CACHE_OBJECT_STORE, this._getId(url));
|
|
58
56
|
return entry?.timestamp;
|
|
59
57
|
}
|
|
60
58
|
async expireEntries(minTimestamp, maxCount) {
|
|
@@ -13,6 +13,14 @@ export declare class CacheTimestampsModel {
|
|
|
13
13
|
* @private
|
|
14
14
|
*/
|
|
15
15
|
constructor(cacheName: string);
|
|
16
|
+
/**
|
|
17
|
+
* Takes a URL and returns an ID that will be unique in the object store.
|
|
18
|
+
*
|
|
19
|
+
* @param url
|
|
20
|
+
* @returns
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
private _getId;
|
|
16
24
|
/**
|
|
17
25
|
* Performs an upgrade of indexedDB.
|
|
18
26
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CacheTimestampsModel.d.ts","sourceRoot":"","sources":["../../src/models/CacheTimestampsModel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CacheTimestampsModel.d.ts","sourceRoot":"","sources":["../../src/models/CacheTimestampsModel.ts"],"names":[],"mappings":"AAoCA;;;;GAIG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,GAAG,CAA4C;IAEvD;;;;;OAKG;gBACS,SAAS,EAAE,MAAM;IAI7B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM;IAId;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;IAYlB;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;IAOjC;;;;;OAKG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBjE;;;;;;OAMG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAM5D;;;;;;;;;OASG;IACG,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAyB/E;;;;OAIG;YACW,KAAK;CAQpB"}
|
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.17",
|
|
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.17"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"rollup": "4.13.0",
|
|
37
37
|
"typescript": "5.5.0-dev.20240323",
|
|
38
|
-
"@serwist/constants": "9.0.0-preview.
|
|
38
|
+
"@serwist/constants": "9.0.0-preview.17"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"typescript": ">=5.0.0"
|
package/src/CacheExpiration.ts
CHANGED
package/src/ExpirationPlugin.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface ExpirationPluginOptions {
|
|
|
25
25
|
/**
|
|
26
26
|
* Determines whether `maxAgeSeconds` should be calculated from when an
|
|
27
27
|
* entry was last fetched or when it was last used.
|
|
28
|
-
*
|
|
28
|
+
*
|
|
29
29
|
* @default "last-fetched"
|
|
30
30
|
*/
|
|
31
31
|
maxAgeFrom?: "last-fetched" | "last-used";
|
|
@@ -20,6 +20,7 @@ const normalizeURL = (unNormalizedUrl: string) => {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
interface CacheTimestampsModelEntry {
|
|
23
|
+
id: string;
|
|
23
24
|
cacheName: string;
|
|
24
25
|
url: string;
|
|
25
26
|
timestamp: number;
|
|
@@ -27,7 +28,7 @@ interface CacheTimestampsModelEntry {
|
|
|
27
28
|
|
|
28
29
|
interface CacheDbSchema extends DBSchema {
|
|
29
30
|
"cache-entries": {
|
|
30
|
-
key:
|
|
31
|
+
key: string;
|
|
31
32
|
value: CacheTimestampsModelEntry;
|
|
32
33
|
indexes: { cacheName: string; timestamp: number };
|
|
33
34
|
};
|
|
@@ -52,6 +53,17 @@ export class CacheTimestampsModel {
|
|
|
52
53
|
this._cacheName = cacheName;
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Takes a URL and returns an ID that will be unique in the object store.
|
|
58
|
+
*
|
|
59
|
+
* @param url
|
|
60
|
+
* @returns
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
private _getId(url: string): string {
|
|
64
|
+
return `${this._cacheName}|${normalizeURL(url)}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
55
67
|
/**
|
|
56
68
|
* Performs an upgrade of indexedDB.
|
|
57
69
|
*
|
|
@@ -61,7 +73,7 @@ export class CacheTimestampsModel {
|
|
|
61
73
|
*/
|
|
62
74
|
private _upgradeDb(db: IDBPDatabase<CacheDbSchema>) {
|
|
63
75
|
const objStore = db.createObjectStore(CACHE_OBJECT_STORE, {
|
|
64
|
-
keyPath:
|
|
76
|
+
keyPath: "id",
|
|
65
77
|
});
|
|
66
78
|
|
|
67
79
|
// TODO(philipwalton): once we don't have to support EdgeHTML, we can
|
|
@@ -95,6 +107,7 @@ export class CacheTimestampsModel {
|
|
|
95
107
|
url = normalizeURL(url);
|
|
96
108
|
|
|
97
109
|
const entry = {
|
|
110
|
+
id: this._getId(url),
|
|
98
111
|
cacheName: this._cacheName,
|
|
99
112
|
url,
|
|
100
113
|
timestamp,
|
|
@@ -116,7 +129,7 @@ export class CacheTimestampsModel {
|
|
|
116
129
|
*/
|
|
117
130
|
async getTimestamp(url: string): Promise<number | undefined> {
|
|
118
131
|
const db = await this.getDb();
|
|
119
|
-
const entry = await db.get(CACHE_OBJECT_STORE,
|
|
132
|
+
const entry = await db.get(CACHE_OBJECT_STORE, this._getId(url));
|
|
120
133
|
return entry?.timestamp;
|
|
121
134
|
}
|
|
122
135
|
|