Skip to content

Commit 9a27dc2

Browse files
committed
WC-4389 Reduce ttl to 10s for asset-worker
1 parent 8520a9c commit 9a27dc2

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

.changeset/bright-eggs-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/workers-shared": patch
3+
---
4+
5+
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.

packages/workers-shared/asset-worker/src/utils/kv.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ export async function getAssetWithMetadataFromKV(
2323
);
2424

2525
if (asset.value === null) {
26-
// Don't cache a 404 for a year by re-requesting with a minimum cacheTtl
26+
// Don't cache a 404 for a year by re-requesting with a short cacheTtl
2727
const retriedAsset =
2828
await assetsKVNamespace.getWithMetadata<AssetMetadata>(assetKey, {
2929
type: "stream",
30-
cacheTtl: 60, // Minimum value allowed
30+
cacheTtl: 10,
3131
});
3232

3333
if (retriedAsset.value !== null && sentry) {

packages/workers-shared/asset-worker/tests/kv.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe("[Asset Worker] Fetching assets from KV", () => {
7878
expect(spy).toHaveBeenCalledTimes(2);
7979
});
8080

81-
it("should retry on 404 and cache with 30s ttl", async () => {
81+
it("should retry on 404 with short cache ttl", async () => {
8282
let attempts = 0;
8383
spy.mockImplementation(() => {
8484
if (attempts++ === 0) {

0 commit comments

Comments
 (0)