Skip to content

Commit f49f9d5

Browse files
committed
fixup! apply default values in computeCacheKey
1 parent f934521 commit f49f9d5

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

packages/cloudflare/src/api/overrides/incremental-cache/kv-incremental-cache.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export type KeyOptions = {
1919
export function computeCacheKey(key: string, options: KeyOptions) {
2020
const { isFetch, buildId } = options;
2121
const hash = createHash("sha256");
22-
return `${buildId}/${hash.update(key).digest("hex")}.${isFetch ? "fetch" : "cache"}`.replace(/\/+/g, "/");
22+
return `${buildId ?? FALLBACK_BUILD_ID}/${hash.update(key).digest("hex")}.${isFetch ? "fetch" : "cache"}`.replace(
23+
/\/+/g,
24+
"/"
25+
);
2326
}
2427

2528
/**
@@ -107,7 +110,7 @@ class KVIncrementalCache implements IncrementalCache {
107110

108111
protected getKVKey(key: string, isFetch?: boolean): string {
109112
return computeCacheKey(key, {
110-
buildId: process.env.NEXT_BUILD_ID ?? FALLBACK_BUILD_ID,
113+
buildId: process.env.NEXT_BUILD_ID,
111114
isFetch: Boolean(isFetch),
112115
});
113116
}

packages/cloudflare/src/api/overrides/incremental-cache/r2-incremental-cache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type KeyOptions = {
2323
export function computeCacheKey(key: string, options: KeyOptions) {
2424
const { isFetch, directory, buildId } = options;
2525
const hash = createHash("sha256");
26-
return `${directory}/${buildId}/${hash.update(key).digest("hex")}.${isFetch ? "fetch" : "cache"}`.replace(
26+
return `${directory ?? DEFAULT_PREFIX}/${buildId ?? FALLBACK_BUILD_ID}/${hash.update(key).digest("hex")}.${isFetch ? "fetch" : "cache"}`.replace(
2727
/\/+/g,
2828
"/"
2929
);
@@ -94,8 +94,8 @@ class R2IncrementalCache implements IncrementalCache {
9494

9595
protected getR2Key(key: string, isFetch?: boolean): string {
9696
return computeCacheKey(key, {
97-
directory: getCloudflareContext().env[PREFIX_ENV_NAME] ?? DEFAULT_PREFIX,
98-
buildId: process.env.NEXT_BUILD_ID ?? FALLBACK_BUILD_ID,
97+
directory: getCloudflareContext().env[PREFIX_ENV_NAME],
98+
buildId: process.env.NEXT_BUILD_ID,
9999
isFetch: Boolean(isFetch),
100100
});
101101
}

packages/cloudflare/src/cli/commands/populate-cache.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
import {
2323
BINDING_NAME as R2_CACHE_BINDING_NAME,
2424
computeCacheKey as computeR2CacheKey,
25-
DEFAULT_PREFIX as R2_CACHE_DEFAULT_PREFIX,
2625
NAME as R2_CACHE_NAME,
2726
PREFIX_ENV_NAME as R2_CACHE_PREFIX_ENV_NAME,
2827
} from "../../api/overrides/incremental-cache/r2-incremental-cache.js";
@@ -115,7 +114,7 @@ function populateR2IncrementalCache(
115114

116115
for (const { fullPath, key, buildId, isFetch } of tqdm(assets)) {
117116
const cacheKey = computeR2CacheKey(key, {
118-
directory: process.env[R2_CACHE_PREFIX_ENV_NAME] ?? R2_CACHE_DEFAULT_PREFIX,
117+
directory: process.env[R2_CACHE_PREFIX_ENV_NAME],
119118
buildId,
120119
isFetch,
121120
});

0 commit comments

Comments
 (0)