@nxtedition/nxt-undici 6.2.24 → 6.2.25
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/lib/sqlite-cache-store.js +11 -3
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DatabaseSync } from 'node:sqlite'
|
|
2
2
|
import assert from 'node:assert'
|
|
3
|
-
import { parseRangeHeader } from './utils.js'
|
|
3
|
+
import { parseRangeHeader, getFastNow } from './utils.js'
|
|
4
4
|
|
|
5
5
|
const VERSION = 6
|
|
6
6
|
|
|
@@ -45,6 +45,11 @@ export class SqliteCacheStore {
|
|
|
45
45
|
*/
|
|
46
46
|
#deleteExpiredValuesQuery
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @type {number}
|
|
50
|
+
*/
|
|
51
|
+
#deleteExpiredValuesTime = getFastNow()
|
|
52
|
+
|
|
48
53
|
/**
|
|
49
54
|
* @type {import('node:sqlite').StatementSync}
|
|
50
55
|
*/
|
|
@@ -160,7 +165,10 @@ export class SqliteCacheStore {
|
|
|
160
165
|
assert(Number.isFinite(value.end))
|
|
161
166
|
assert(!body || body?.byteLength === value.end - value.start)
|
|
162
167
|
|
|
163
|
-
|
|
168
|
+
const now = getFastNow()
|
|
169
|
+
if (now > this.#deleteExpiredValuesTime + 60e3) {
|
|
170
|
+
this.#deleteExpiredValuesQuery.run(now)
|
|
171
|
+
}
|
|
164
172
|
|
|
165
173
|
this.#insertValueQuery.run(
|
|
166
174
|
makeValueUrl(key),
|
|
@@ -214,7 +222,7 @@ export class SqliteCacheStore {
|
|
|
214
222
|
return undefined
|
|
215
223
|
}
|
|
216
224
|
|
|
217
|
-
const now =
|
|
225
|
+
const now = getFastNow()
|
|
218
226
|
for (const value of values) {
|
|
219
227
|
if (now >= value.deleteAt && !canBeExpired) {
|
|
220
228
|
return undefined
|