Skip to content

Commit 292673a

Browse files
bump aws package and add comment
1 parent 983a89f commit 292673a

File tree

4 files changed

+25
-35
lines changed

4 files changed

+25
-35
lines changed

.changeset/fluffy-taxis-rescue.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@opennextjs/cloudflare": patch
33
---
44

5-
bump `@opennextjs/aws` dependency to `https://pkg.pr.new/@opennextjs/aws@726`
5+
bump `@opennextjs/aws` dependency to `https://pkg.pr.new/@opennextjs/aws@727`

packages/cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"dependencies": {
7474
"@ast-grep/napi": "^0.34.1",
7575
"@dotenvx/dotenvx": "catalog:",
76-
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@726",
76+
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@727",
7777
"enquirer": "^2.4.1",
7878
"glob": "catalog:",
7979
"ts-morph": "catalog:",

packages/cloudflare/src/api/kvCache.ts

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { CacheValue, IncrementalCache, WithLastModified } from "@opennextjs/aws/types/overrides";
1+
import type {
2+
CachedFetchValue,
3+
CacheValue,
4+
IncrementalCache,
5+
WithLastModified,
6+
} from "@opennextjs/aws/types/overrides";
27
import { IgnorableError, RecoverableError } from "@opennextjs/aws/utils/error.js";
38

49
import { getCloudflareContext } from "./cloudflare-context.js";
@@ -7,23 +12,6 @@ export const CACHE_ASSET_DIR = "cnd-cgi/_next_cache";
712

813
export const STATUS_DELETED = 1;
914

10-
// https://github.com/vercel/next.js/blob/9a1cd356/packages/next/src/server/response-cache/types.ts#L26-L38
11-
export type CachedFetchValue = {
12-
kind: "FETCH";
13-
data: {
14-
headers: { [k: string]: string };
15-
body: string;
16-
url: string;
17-
status?: number;
18-
// field used by older versions of Next.js (see: https://github.com/vercel/next.js/blob/fda1ecc/packages/next/src/server/response-cache/types.ts#L23)
19-
tags?: string[];
20-
};
21-
// tags are only present with file-system-cache
22-
// fetch cache stores tags outside of cache entry
23-
tags?: string[];
24-
revalidate: number;
25-
};
26-
2715
/**
2816
* Open Next cache based on cloudflare KV and Assets.
2917
*
@@ -78,15 +66,17 @@ class Cache implements IncrementalCache {
7866
lastModified: (globalThis as { __BUILD_TIMESTAMP_MS__?: number }).__BUILD_TIMESTAMP_MS__,
7967
};
8068
}
81-
}
82-
83-
const entryValue = entry?.value as CachedFetchValue | undefined;
84-
if (entryValue?.kind === "FETCH") {
85-
const expires = entryValue.data.headers?.expires;
86-
const expiresTime = new Date(expires as string).getTime();
87-
if (!isNaN(expiresTime) && expiresTime <= Date.now()) {
88-
this.debug(`found expired entry (expire time: ${expires})`);
89-
return null;
69+
// if we were unable to get the cached data from the KV we get it from the assets generated at build time
70+
// however before serving them we need to make sure that they are not expired, otherwise if the KV cache
71+
// is missing or not working properly we end up always serving the same stale build time generated cache entries
72+
const entryValue = entry?.value as CachedFetchValue;
73+
if (entryValue?.kind === "FETCH") {
74+
const expires = entryValue.data.headers?.expires;
75+
const expiresTime = new Date(expires as string).getTime();
76+
if (!isNaN(expiresTime) && expiresTime <= Date.now()) {
77+
this.debug(`found expired entry (expire time: ${expires})`);
78+
return null;
79+
}
9080
}
9181
}
9282

pnpm-lock.yaml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)