Skip to content

Commit 8566368

Browse files
committed
comments
1 parent 039dc1b commit 8566368

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getCloudflareContext } from "./cloudflare-context.js";
88
* An instance of the Incremental Cache that uses an R2 bucket (`NEXT_CACHE_R2_BUCKET`) as it's
99
* underlying data store.
1010
*
11-
* The directory that the cache entries are stored in can be confused with the `NEXT_CACHE_R2_PREFIX`
11+
* The directory that the cache entries are stored in can be configured with the `NEXT_CACHE_R2_PREFIX`
1212
* environment variable, and defaults to `incremental-cache`.
1313
*
1414
* The cache uses an instance of the Cache API (`incremental-cache`) to store a local version of the
@@ -17,6 +17,12 @@ import { getCloudflareContext } from "./cloudflare-context.js";
1717
class R2IncrementalCache implements IncrementalCache {
1818
readonly name = "r2-incremental-cache";
1919

20+
protected directory: string;
21+
22+
constructor() {
23+
this.directory = getCloudflareContext().env.NEXT_CACHE_R2_PREFIX ?? "incremental-cache";
24+
}
25+
2026
async get<IsFetch extends boolean = false>(
2127
key: string,
2228
isFetch?: IsFetch
@@ -71,9 +77,7 @@ class R2IncrementalCache implements IncrementalCache {
7177
}
7278

7379
protected getR2Key(key: string, isFetch?: boolean): string {
74-
const directory = getCloudflareContext().env.NEXT_CACHE_R2_PREFIX ?? "incremental-cache";
75-
76-
return `${directory}/${process.env.NEXT_BUILD_ID ?? "no-build-id"}/${key}.${isFetch ? "fetch" : "cache"}`;
80+
return `${this.directory}/${process.env.NEXT_BUILD_ID ?? "no-build-id"}/${key}.${isFetch ? "fetch" : "cache"}`;
7781
}
7882
}
7983

packages/cloudflare/src/api/regional-cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Options = {
1212
* The mode to use for the regional cache.
1313
*
1414
* - `short-lived`: Re-use a cache entry for up to a minute after it has been retrieved.
15-
* - `long-lived`: Re-use a fetch cache entry until it is revalidated, or an ISR/SSG entry for up to 30 minutes.
15+
* - `long-lived`: Re-use a fetch cache entry until it is revalidated (per-region), or an ISR/SSG entry for up to 30 minutes.
1616
*/
1717
mode: "short-lived" | "long-lived";
1818
/**
@@ -156,7 +156,7 @@ class RegionalCache implements IncrementalCache {
156156
* @param cache - Incremental cache instance.
157157
* @param opts.mode - The mode to use for the regional cache.
158158
* - `short-lived`: Re-use a cache entry for up to a minute after it has been retrieved.
159-
* - `long-lived`: Re-use a fetch cache entry until it is revalidated, or an ISR/SSG entry for up to 30 minutes.
159+
* - `long-lived`: Re-use a fetch cache entry until it is revalidated (per-region), or an ISR/SSG entry for up to 30 minutes.
160160
* @param opts.shouldLazilyUpdateOnCacheHit - Whether the regional cache entry should be updated in
161161
* the background or not when it experiences a cache hit.
162162
*

packages/cloudflare/src/cli/build/utils/populate-cache.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ function runWrangler(
5252
}
5353

5454
function getCacheAssetPaths(opts: BuildOptions) {
55-
return globSync(path.join(opts.outputDir, "cache/**/*"), { withFileTypes: true })
55+
return globSync(path.join(opts.outputDir, "cache/**/*"), {
56+
withFileTypes: true,
57+
windowsPathsNoEscape: true,
58+
})
5659
.filter((f) => f.isFile())
5760
.map((f) => {
5861
const relativePath = path.relative(path.join(opts.outputDir, "cache"), f.fullpathPosix());

0 commit comments

Comments
 (0)