@nxtedition/lib 26.0.7 → 26.0.8
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/cache.js +21 -6
- package/http.js +3 -1
- package/package.json +1 -1
package/cache.js
CHANGED
|
@@ -55,7 +55,8 @@ export class AsyncCache {
|
|
|
55
55
|
throw new TypeError('stale must be a undefined, number or a function')
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
this.#lru =
|
|
58
|
+
this.#lru =
|
|
59
|
+
opts?.lru === false || opts?.lru === null ? null : new LRUCache({ max: 4096, ...opts?.lru })
|
|
59
60
|
this.#db = new DatabaseSync(location, { timeout: 20, ...opts?.db })
|
|
60
61
|
this.#db.exec(`
|
|
61
62
|
PRAGMA journal_mode = WAL;
|
|
@@ -95,7 +96,7 @@ export class AsyncCache {
|
|
|
95
96
|
|
|
96
97
|
const now = fastNow()
|
|
97
98
|
|
|
98
|
-
let cached = this.#lru
|
|
99
|
+
let cached = this.#lru?.get(key)
|
|
99
100
|
|
|
100
101
|
if (cached === undefined) {
|
|
101
102
|
try {
|
|
@@ -106,7 +107,7 @@ export class AsyncCache {
|
|
|
106
107
|
stale: ret.stale,
|
|
107
108
|
value: JSON.parse(ret.val),
|
|
108
109
|
}
|
|
109
|
-
this.#lru
|
|
110
|
+
this.#lru?.set(key, cached)
|
|
110
111
|
}
|
|
111
112
|
} catch {
|
|
112
113
|
// Do nothing...
|
|
@@ -120,9 +121,9 @@ export class AsyncCache {
|
|
|
120
121
|
|
|
121
122
|
if (now > cached.stale) {
|
|
122
123
|
// stale-while-revalidate has ttld, purge cached value.
|
|
123
|
-
this.#lru
|
|
124
|
+
this.#lru?.delete(key)
|
|
124
125
|
try {
|
|
125
|
-
this.#delQuery
|
|
126
|
+
this.#delQuery?.run(key)
|
|
126
127
|
} catch {
|
|
127
128
|
// Do nothing...
|
|
128
129
|
}
|
|
@@ -171,7 +172,7 @@ export class AsyncCache {
|
|
|
171
172
|
value,
|
|
172
173
|
}
|
|
173
174
|
|
|
174
|
-
this.#lru
|
|
175
|
+
this.#lru?.set(key, cached)
|
|
175
176
|
this.#dedupe.delete(key)
|
|
176
177
|
|
|
177
178
|
try {
|
|
@@ -180,4 +181,18 @@ export class AsyncCache {
|
|
|
180
181
|
// Do nothing...
|
|
181
182
|
}
|
|
182
183
|
}
|
|
184
|
+
|
|
185
|
+
delete(key) {
|
|
186
|
+
if (typeof key !== 'string' || key.length === 0) {
|
|
187
|
+
throw new TypeError('key must be a non-empty string')
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
this.#lru?.delete(key)
|
|
191
|
+
|
|
192
|
+
try {
|
|
193
|
+
this.#delQuery?.run(key)
|
|
194
|
+
} catch {
|
|
195
|
+
// Do nothing...
|
|
196
|
+
}
|
|
197
|
+
}
|
|
183
198
|
}
|
package/http.js
CHANGED
|
@@ -166,7 +166,9 @@ export async function upgradeMiddleware(ctx, next) {
|
|
|
166
166
|
await thenable
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
if (!socket.destroyed && !socket.writableEnded) {
|
|
170
|
+
throw new Error('Stream not completed')
|
|
171
|
+
}
|
|
170
172
|
|
|
171
173
|
const elapsedTime = performance.now() - startTime
|
|
172
174
|
|