diff --git a/.changeset/bright-eggs-draw.md b/.changeset/bright-eggs-draw.md new file mode 100644 index 000000000000..220191be2c3f --- /dev/null +++ b/.changeset/bright-eggs-draw.md @@ -0,0 +1,5 @@ +--- +"@cloudflare/workers-shared": patch +--- + +The asset-worker now uses a shorter 10-second TTL for cached assets, down from 60 seconds. This ensures that asset updates are reflected more quickly during development and deployment, reducing the window where stale assets might be served. diff --git a/packages/workers-shared/asset-worker/src/utils/kv.ts b/packages/workers-shared/asset-worker/src/utils/kv.ts index e55af80a0a60..61e11755a6ff 100644 --- a/packages/workers-shared/asset-worker/src/utils/kv.ts +++ b/packages/workers-shared/asset-worker/src/utils/kv.ts @@ -23,11 +23,11 @@ export async function getAssetWithMetadataFromKV( ); if (asset.value === null) { - // Don't cache a 404 for a year by re-requesting with a minimum cacheTtl + // Don't cache a 404 for a year by re-requesting with a short cacheTtl const retriedAsset = await assetsKVNamespace.getWithMetadata(assetKey, { type: "stream", - cacheTtl: 60, // Minimum value allowed + cacheTtl: 10, }); if (retriedAsset.value !== null && sentry) { diff --git a/packages/workers-shared/asset-worker/tests/kv.test.ts b/packages/workers-shared/asset-worker/tests/kv.test.ts index ef6df342b9f7..6db6dbeb19ba 100644 --- a/packages/workers-shared/asset-worker/tests/kv.test.ts +++ b/packages/workers-shared/asset-worker/tests/kv.test.ts @@ -78,7 +78,7 @@ describe("[Asset Worker] Fetching assets from KV", () => { expect(spy).toHaveBeenCalledTimes(2); }); - it("should retry on 404 and cache with 30s ttl", async () => { + it("should retry on 404 with short cache ttl", async () => { let attempts = 0; spy.mockImplementation(() => { if (attempts++ === 0) {