File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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";
1717class 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
Original file line number Diff line number Diff 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 *
Original file line number Diff line number Diff line change @@ -52,7 +52,10 @@ function runWrangler(
5252}
5353
5454function 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 ( ) ) ;
You can’t perform that action at this time.
0 commit comments