Skip to content

Commit

Permalink
fix(pages-shared) Remove request method from cache key (#5785)
Browse files Browse the repository at this point in the history
  • Loading branch information
jahands committed May 8, 2024
1 parent f3c0fff commit c0b057b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changeset/old-students-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cloudflare/pages-shared": patch
---

fix: Remove request method from cache key

Reverts a change that added the request method to the cache key when reading/writing to cache.
13 changes: 3 additions & 10 deletions packages/pages-shared/asset-server/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,6 @@ export async function generateHandler<

return await attachHeaders(await generateResponse());

/** We have non-standard cache behavior, so strip out all headers but keep the method */
function getCacheKey(): Request {
return new Request(request.url, {
method: request.method,
});
}

async function serveAsset(
servingAssetEntry: AssetEntry,
options = { preserve: true }
Expand Down Expand Up @@ -580,7 +573,7 @@ export async function generateHandler<
preservedResponse.headers.set("x-robots-tag", "noindex");

await assetPreservationCacheV2.put(
getCacheKey(),
request.url,
preservedResponse
);
}
Expand Down Expand Up @@ -621,12 +614,12 @@ export async function generateHandler<
ASSET_PRESERVATION_CACHE_V2
);
let preservedResponse = await assetPreservationCacheV2.match(
getCacheKey()
request.url
);

// Continue serving from V1 preservation cache for some time to
// prevent 404s during the migration to V2
const cutoffDate = new Date("2024-05-10");
const cutoffDate = new Date("2024-05-17");
if (!preservedResponse && Date.now() < cutoffDate.getTime()) {
const assetPreservationCacheV1 = await caches.open(
ASSET_PRESERVATION_CACHE_V1
Expand Down

0 comments on commit c0b057b

Please sign in to comment.