Skip to content

Commit e382866

Browse files
committed
fixup! simplify
1 parent 84d9eb8 commit e382866

File tree

5 files changed

+9
-20
lines changed

5 files changed

+9
-20
lines changed

examples/e2e/app-router/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NEXT_PRIVATE_DEBUG_CACHE=1

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { createHash, type Hash } from "node:crypto";
1+
import { createHash } from "node:crypto";
22

33
import { error } from "@opennextjs/aws/adapters/logger.js";
44
import type { CacheValue, IncrementalCache, WithLastModified } from "@opennextjs/aws/types/overrides.js";
55
import { IgnorableError } from "@opennextjs/aws/utils/error.js";
66

77
import { getCloudflareContext } from "../../cloudflare-context.js";
8-
import { CACHE_KEY_HASH, debugCache, FALLBACK_BUILD_ID, IncrementalCacheEntry } from "../internal.js";
8+
import { debugCache, FALLBACK_BUILD_ID, IncrementalCacheEntry } from "../internal.js";
99

1010
export const NAME = "cf-kv-incremental-cache";
1111

@@ -14,11 +14,11 @@ export const BINDING_NAME = "NEXT_INC_CACHE_KV";
1414
export type KeyOptions = {
1515
isFetch: boolean;
1616
buildId?: string;
17-
hash: Hash;
1817
};
1918

2019
export function computeCacheKey(key: string, options: KeyOptions) {
21-
const { isFetch, buildId, hash } = options;
20+
const { isFetch, buildId } = options;
21+
const hash = createHash("sha256");
2222
return `${buildId}/${hash.update(key).digest("hex")}.${isFetch ? "fetch" : "cache"}`.replace(/\/+/g, "/");
2323
}
2424

@@ -109,7 +109,6 @@ class KVIncrementalCache implements IncrementalCache {
109109
return computeCacheKey(key, {
110110
buildId: process.env.NEXT_BUILD_ID ?? FALLBACK_BUILD_ID,
111111
isFetch: Boolean(isFetch),
112-
hash: createHash(CACHE_KEY_HASH),
113112
});
114113
}
115114
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { createHash, type Hash } from "node:crypto";
1+
import { createHash } from "node:crypto";
22

33
import { error } from "@opennextjs/aws/adapters/logger.js";
44
import type { CacheValue, IncrementalCache, WithLastModified } from "@opennextjs/aws/types/overrides.js";
55
import { IgnorableError } from "@opennextjs/aws/utils/error.js";
66

77
import { getCloudflareContext } from "../../cloudflare-context.js";
8-
import { CACHE_KEY_HASH, debugCache, FALLBACK_BUILD_ID } from "../internal.js";
8+
import { debugCache, FALLBACK_BUILD_ID } from "../internal.js";
99

1010
export const NAME = "cf-r2-incremental-cache";
1111

@@ -18,11 +18,11 @@ export type KeyOptions = {
1818
isFetch: boolean;
1919
directory?: string;
2020
buildId?: string;
21-
hash: Hash;
2221
};
2322

2423
export function computeCacheKey(key: string, options: KeyOptions) {
25-
const { isFetch, directory, buildId, hash } = options;
24+
const { isFetch, directory, buildId } = options;
25+
const hash = createHash("sha256");
2626
return `${directory}/${buildId}/${hash.update(key).digest("hex")}.${isFetch ? "fetch" : "cache"}`.replace(
2727
/\/+/g,
2828
"/"
@@ -97,7 +97,6 @@ class R2IncrementalCache implements IncrementalCache {
9797
directory: getCloudflareContext().env[PREFIX_ENV_NAME] ?? DEFAULT_PREFIX,
9898
buildId: process.env.NEXT_BUILD_ID ?? FALLBACK_BUILD_ID,
9999
isFetch: Boolean(isFetch),
100-
hash: createHash(CACHE_KEY_HASH),
101100
});
102101
}
103102
}

packages/cloudflare/src/api/overrides/internal.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,4 @@ export const debugCache = (name: string, ...args: unknown[]) => {
1111
}
1212
};
1313

14-
// Hash the keys to limit their length.
15-
// KV has a limit of 512B, R2 has a limit of 1024B.
16-
export const CACHE_KEY_HASH = "sha256";
17-
1814
export const FALLBACK_BUILD_ID = "no-build-id";

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { createHash } from "node:crypto";
21
import { cpSync, existsSync } from "node:fs";
32
import path from "node:path";
43

@@ -31,7 +30,6 @@ import {
3130
CACHE_DIR as STATIC_ASSETS_CACHE_DIR,
3231
NAME as STATIC_ASSETS_CACHE_NAME,
3332
} from "../../api/overrides/incremental-cache/static-assets-incremental-cache.js";
34-
import { CACHE_KEY_HASH } from "../../api/overrides/internal.js";
3533
import {
3634
BINDING_NAME as D1_TAG_BINDING_NAME,
3735
NAME as D1_TAG_NAME,
@@ -122,11 +120,8 @@ function populateR2IncrementalCache(
122120
directory: process.env[R2_CACHE_PREFIX_ENV_NAME] ?? R2_CACHE_DEFAULT_PREFIX,
123121
buildId,
124122
isFetch,
125-
hash: createHash(CACHE_KEY_HASH),
126123
});
127124

128-
console.error({ cacheKey, key });
129-
130125
runWrangler(
131126
options,
132127
["r2 object put", JSON.stringify(path.join(bucket, cacheKey)), `--file ${JSON.stringify(fullPath)}`],
@@ -157,7 +152,6 @@ function populateKVIncrementalCache(
157152
const cacheKey = computeKVCacheKey(key, {
158153
buildId,
159154
isFetch,
160-
hash: createHash(CACHE_KEY_HASH),
161155
});
162156

163157
runWrangler(

0 commit comments

Comments
 (0)