@cloudflare/pages-shared 0.11.71 → 0.11.72

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.
@@ -25,10 +25,8 @@ type BodyEncoding = "manual" | "automatic";
25
25
  // Before serving a 404, we check the cache to see if we've served this asset recently
26
26
  // and if so, serve it from the cache instead of responding with a 404.
27
27
  // This gives a bit of a grace period between deployments for any clients browsing the old deployment.
28
- export const ASSET_PRESERVATION_CACHE_V1 = "assetPreservationCache";
29
- // V2 stores the content hash instead of the asset.
30
- // TODO: Remove V1 once we've fully migrated to V2
31
- export const ASSET_PRESERVATION_CACHE_V2 = "assetPreservationCacheV2";
28
+ // Only the content hash is actually stored in the body.
29
+ export const ASSET_PRESERVATION_CACHE = "assetPreservationCacheV2";
32
30
  const CACHE_CONTROL_PRESERVATION = "public, s-maxage=604800"; // 1 week
33
31
 
34
32
  /** The preservation cache should be periodically
@@ -576,14 +574,14 @@ export async function generateHandler<
576
574
  waitUntil(
577
575
  (async () => {
578
576
  try {
579
- const assetPreservationCacheV2 = await caches.open(
580
- ASSET_PRESERVATION_CACHE_V2
577
+ const assetPreservationCache = await caches.open(
578
+ ASSET_PRESERVATION_CACHE
581
579
  );
582
580
 
583
581
  // Check if the asset has changed since last written to cache
584
582
  // or if the cached entry is getting too old and should have
585
583
  // it's expiration reset.
586
- const match = await assetPreservationCacheV2.match(request);
584
+ const match = await assetPreservationCache.match(request);
587
585
  if (
588
586
  !match ||
589
587
  assetKey !== (await match.text()) ||
@@ -599,7 +597,7 @@ export async function generateHandler<
599
597
  );
600
598
  preservedResponse.headers.set("x-robots-tag", "noindex");
601
599
 
602
- await assetPreservationCacheV2.put(
600
+ await assetPreservationCache.put(
603
601
  request.url,
604
602
  preservedResponse
605
603
  );
@@ -637,30 +635,13 @@ export async function generateHandler<
637
635
  async function notFound(): Promise<Response> {
638
636
  if (caches) {
639
637
  try {
640
- const assetPreservationCacheV2 = await caches.open(
641
- ASSET_PRESERVATION_CACHE_V2
638
+ const assetPreservationCache = await caches.open(
639
+ ASSET_PRESERVATION_CACHE
642
640
  );
643
- let preservedResponse = await assetPreservationCacheV2.match(
641
+ const preservedResponse = await assetPreservationCache.match(
644
642
  request.url
645
643
  );
646
644
 
647
- // Continue serving from V1 preservation cache for some time to
648
- // prevent 404s during the migration to V2
649
- const cutoffDate = new Date("2024-05-17");
650
- if (!preservedResponse && Date.now() < cutoffDate.getTime()) {
651
- const assetPreservationCacheV1 = await caches.open(
652
- ASSET_PRESERVATION_CACHE_V1
653
- );
654
- preservedResponse = await assetPreservationCacheV1.match(request.url);
655
- if (preservedResponse) {
656
- // V1 cache contains full response bodies so we return it directly
657
- if (setMetrics) {
658
- setMetrics({ preservationCacheResult: "checked-hit" });
659
- }
660
- return preservedResponse;
661
- }
662
- }
663
-
664
645
  // V2 cache only contains the asset key, rather than the asset body:
665
646
  if (preservedResponse) {
666
647
  if (setMetrics) {
@@ -674,6 +655,7 @@ export async function generateHandler<
674
655
  }
675
656
  if (assetKey) {
676
657
  const asset = await fetchAsset(assetKey);
658
+
677
659
  if (asset) {
678
660
  // We know the asset hasn't changed, so use the cached headers.
679
661
  return new Response(asset.body, preservedResponse);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/pages-shared",
3
- "version": "0.11.71",
3
+ "version": "0.11.72",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cloudflare/workers-sdk.git",