@nxtedition/nxt-undici 6.2.23 → 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 -11
- 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
|
|
|
@@ -46,14 +46,14 @@ export class SqliteCacheStore {
|
|
|
46
46
|
#deleteExpiredValuesQuery
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* @type {
|
|
49
|
+
* @type {number}
|
|
50
50
|
*/
|
|
51
|
-
#
|
|
51
|
+
#deleteExpiredValuesTime = getFastNow()
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* @type {
|
|
54
|
+
* @type {import('node:sqlite').StatementSync}
|
|
55
55
|
*/
|
|
56
|
-
#
|
|
56
|
+
#deleteByUrlQuery
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* @param {import('undici-types/cache-interceptor.d.ts').default.SqliteCacheStoreOpts & { maxEntryCount?: number} | undefined} opts
|
|
@@ -134,14 +134,9 @@ export class SqliteCacheStore {
|
|
|
134
134
|
this.#deleteExpiredValuesQuery = this.#db.prepare(
|
|
135
135
|
`DELETE FROM cacheInterceptorV${VERSION} WHERE deleteAt <= ?`,
|
|
136
136
|
)
|
|
137
|
-
|
|
138
|
-
this.#pruneInterval = setInterval(() => {
|
|
139
|
-
this.#deleteExpiredValuesQuery.run(Date.now())
|
|
140
|
-
}, 60e3).unref()
|
|
141
137
|
}
|
|
142
138
|
|
|
143
139
|
close() {
|
|
144
|
-
clearInterval(this.#pruneInterval)
|
|
145
140
|
this.#db.close()
|
|
146
141
|
}
|
|
147
142
|
|
|
@@ -170,6 +165,11 @@ export class SqliteCacheStore {
|
|
|
170
165
|
assert(Number.isFinite(value.end))
|
|
171
166
|
assert(!body || body?.byteLength === value.end - value.start)
|
|
172
167
|
|
|
168
|
+
const now = getFastNow()
|
|
169
|
+
if (now > this.#deleteExpiredValuesTime + 60e3) {
|
|
170
|
+
this.#deleteExpiredValuesQuery.run(now)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
173
|
this.#insertValueQuery.run(
|
|
174
174
|
makeValueUrl(key),
|
|
175
175
|
key.method,
|
|
@@ -222,7 +222,7 @@ export class SqliteCacheStore {
|
|
|
222
222
|
return undefined
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
const now =
|
|
225
|
+
const now = getFastNow()
|
|
226
226
|
for (const value of values) {
|
|
227
227
|
if (now >= value.deleteAt && !canBeExpired) {
|
|
228
228
|
return undefined
|