@cloudflare/workers-response-store 1.1.4 → 1.1.5
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/metadata-do.js +10 -4
- package/package.json +1 -1
package/dist/metadata-do.js
CHANGED
|
@@ -4,6 +4,7 @@ import { DurableObject } from "cloudflare:workers";
|
|
|
4
4
|
const REFRESHABLE_ENTRY = `tombstoned = 0 AND active_revision IS NOT NULL
|
|
5
5
|
AND object_key IS NOT NULL AND response_headers IS NOT NULL
|
|
6
6
|
AND fresh_until IS NOT NULL AND swr_until IS NOT NULL`;
|
|
7
|
+
const PRE_UPGRADE_INVALIDATED_REVISION = Number.MAX_SAFE_INTEGER;
|
|
7
8
|
const MAX_SQL_PARAMETERS = 100;
|
|
8
9
|
const ORPHAN_RETENTION_MS = 36e5;
|
|
9
10
|
const ORPHAN_CLEANUP_LIMIT = 100;
|
|
@@ -189,9 +190,9 @@ var CacheMetadata = class extends DurableObject {
|
|
|
189
190
|
if (!migrations.has(9)) {
|
|
190
191
|
if (!(schemas.find(({ name }) => name === "entries")?.sql)?.includes("replaced_revision")) ctx.storage.sql.exec(`
|
|
191
192
|
ALTER TABLE entries ADD COLUMN replaced_revision INTEGER;
|
|
192
|
-
ALTER TABLE entries ADD COLUMN invalidated_revision INTEGER
|
|
193
|
+
ALTER TABLE entries ADD COLUMN invalidated_revision INTEGER
|
|
194
|
+
DEFAULT ${PRE_UPGRADE_INVALIDATED_REVISION};
|
|
193
195
|
`);
|
|
194
|
-
ctx.storage.sql.exec("UPDATE entries SET invalidated_revision = active_revision");
|
|
195
196
|
ctx.storage.sql.exec("INSERT INTO metadata_schema_migrations (version) VALUES (9)");
|
|
196
197
|
}
|
|
197
198
|
if (!migrations.has(10)) {
|
|
@@ -387,7 +388,8 @@ var CacheMetadata = class extends DurableObject {
|
|
|
387
388
|
}
|
|
388
389
|
reserveRevision(keyHash, cacheKey, current) {
|
|
389
390
|
const revision = (current?.latest_revision ?? 0) + 1;
|
|
390
|
-
if (!current) this.ctx.storage.sql.exec(
|
|
391
|
+
if (!current) this.ctx.storage.sql.exec(`INSERT INTO entries (key_hash, cache_key, latest_revision, tombstoned, invalidated_revision)
|
|
392
|
+
VALUES (?, ?, ?, 1, NULL)`, keyHash, cacheKey, revision);
|
|
391
393
|
else this.ctx.storage.sql.exec("UPDATE entries SET cache_key = ?, latest_revision = ? WHERE key_hash = ?", cacheKey, revision, keyHash);
|
|
392
394
|
return revision;
|
|
393
395
|
}
|
|
@@ -495,7 +497,11 @@ var CacheMetadata = class extends DurableObject {
|
|
|
495
497
|
active_revision = ?, object_key = ?, status_text = ?, response_headers = ?,
|
|
496
498
|
fresh_until = ?, swr_until = ?,
|
|
497
499
|
revalidator_id = ?, revalidator_args = ?, expiry_behavior = ?, cache_tags = ?, tombstoned = 0,
|
|
498
|
-
replaced_revision =
|
|
500
|
+
replaced_revision = ?,
|
|
501
|
+
invalidated_revision = CASE invalidated_revision
|
|
502
|
+
WHEN ${PRE_UPGRADE_INVALIDATED_REVISION} THEN active_revision
|
|
503
|
+
ELSE invalidated_revision
|
|
504
|
+
END
|
|
499
505
|
WHERE key_hash = ? AND latest_revision >= ?
|
|
500
506
|
AND (active_revision IS NULL OR active_revision < ?)
|
|
501
507
|
RETURNING key_hash`, revision, metadata.objectKey, metadata.statusText, JSON.stringify(metadata.responseHeaders), freshUntil, swrUntil, metadata.revalidator?.id ?? null, metadata.revalidator ? JSON.stringify(metadata.revalidator.args) : null, metadata.expiryBehavior === "miss" ? "miss" : null, JSON.stringify(metadata.cacheTags), replaces !== void 0 && current.active_revision !== null && replaces.revision <= current.active_revision ? replaces.revision : null, keyHash, revision, revision).toArray().length === 1;
|