@holo-js/cache-db 0.3.20 → 0.3.22
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.mjs +22 -5
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -161,18 +161,26 @@ async function withDatabaseCacheTableGuard(tableName, lockTableName, callback) {
|
|
|
161
161
|
normalizeDatabaseCacheTableError(error, tableName, lockTableName);
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
+
function normalizeDatabaseTimestamp(value) {
|
|
165
|
+
const timestamp = Number(value);
|
|
166
|
+
if (!Number.isSafeInteger(timestamp)) {
|
|
167
|
+
throw new CacheConfigError("[@holo-js/cache] Database cache expiration must be a safe integer timestamp.");
|
|
168
|
+
}
|
|
169
|
+
return timestamp;
|
|
170
|
+
}
|
|
164
171
|
async function readEntry(connection, tableName, key, now) {
|
|
165
172
|
const row = await new TableQueryBuilder(tableName, connection).where("key", key).first();
|
|
166
173
|
if (!row) {
|
|
167
174
|
return { state: "missing" };
|
|
168
175
|
}
|
|
169
|
-
|
|
176
|
+
const expiresAt = row.expires_at === null ? null : normalizeDatabaseTimestamp(row.expires_at);
|
|
177
|
+
if (expiresAt !== null && expiresAt <= now) {
|
|
170
178
|
await new TableQueryBuilder(tableName, connection).where("key", key).delete();
|
|
171
179
|
return { state: "missing" };
|
|
172
180
|
}
|
|
173
181
|
return {
|
|
174
182
|
state: "hit",
|
|
175
|
-
value: row
|
|
183
|
+
value: { ...row, expires_at: expiresAt }
|
|
176
184
|
};
|
|
177
185
|
}
|
|
178
186
|
async function readLock(connection, tableName, name, now) {
|
|
@@ -180,13 +188,14 @@ async function readLock(connection, tableName, name, now) {
|
|
|
180
188
|
if (!row) {
|
|
181
189
|
return { state: "missing" };
|
|
182
190
|
}
|
|
183
|
-
|
|
191
|
+
const expiresAt = normalizeDatabaseTimestamp(row.expires_at);
|
|
192
|
+
if (expiresAt <= now) {
|
|
184
193
|
await new TableQueryBuilder(tableName, connection).where("name", name).delete();
|
|
185
194
|
return { state: "missing" };
|
|
186
195
|
}
|
|
187
196
|
return {
|
|
188
197
|
state: "hit",
|
|
189
|
-
value: row
|
|
198
|
+
value: { ...row, expires_at: expiresAt }
|
|
190
199
|
};
|
|
191
200
|
}
|
|
192
201
|
function createDatabaseLock(connection, tableName, entryTableName, name, seconds, now, sleep, ownerFactory) {
|
|
@@ -301,7 +310,7 @@ function createDatabaseCacheDriver(options) {
|
|
|
301
310
|
}
|
|
302
311
|
return result;
|
|
303
312
|
}
|
|
304
|
-
|
|
313
|
+
const driver = {
|
|
305
314
|
name: options.name,
|
|
306
315
|
driver: "database",
|
|
307
316
|
async get(key) {
|
|
@@ -372,6 +381,14 @@ function createDatabaseCacheDriver(options) {
|
|
|
372
381
|
return createDatabaseLock(connection, lockTableName, entryTableName, name, seconds, now, sleep, ownerFactory);
|
|
373
382
|
}
|
|
374
383
|
};
|
|
384
|
+
Object.defineProperty(driver, /* @__PURE__ */ Symbol.for("holo.cache.driver.dispose"), {
|
|
385
|
+
value() {
|
|
386
|
+
void connection.disconnect().catch((error) => {
|
|
387
|
+
console.error(`[@holo-js/cache-db] Failed to disconnect cache driver "${options.name}".`, error);
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
return driver;
|
|
375
392
|
}
|
|
376
393
|
var databaseCacheDriverFactory = Object.freeze({
|
|
377
394
|
driver: "database",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/cache-db",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.22",
|
|
4
4
|
"description": "Holo-JS Framework - DB-backed cache driver",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,18 +23,18 @@
|
|
|
23
23
|
"test": "vitest --run"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@holo-js/cache": "^0.3.
|
|
27
|
-
"@holo-js/db": "^0.3.
|
|
28
|
-
"@holo-js/kernel": "^0.3.
|
|
26
|
+
"@holo-js/cache": "^0.3.22",
|
|
27
|
+
"@holo-js/db": "^0.3.22",
|
|
28
|
+
"@holo-js/kernel": "^0.3.22"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"tslib": "^2.8.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@holo-js/cache": "^0.3.
|
|
35
|
-
"@holo-js/db": "^0.3.
|
|
36
|
-
"@holo-js/db-sqlite": "^0.3.
|
|
37
|
-
"@holo-js/kernel": "^0.3.
|
|
34
|
+
"@holo-js/cache": "^0.3.22",
|
|
35
|
+
"@holo-js/db": "^0.3.22",
|
|
36
|
+
"@holo-js/db-sqlite": "^0.3.22",
|
|
37
|
+
"@holo-js/kernel": "^0.3.22",
|
|
38
38
|
"@types/node": "^22.10.2",
|
|
39
39
|
"tsup": "^8.3.5",
|
|
40
40
|
"typescript": "^5.7.2",
|