|
8 | 8 |
|
9 | 9 | import { getCloudflareContext } from "../../cloudflare-context.js"; |
10 | 10 | import { debugCache, FALLBACK_BUILD_ID, IncrementalCacheEntry, isPurgeCacheEnabled } from "../internal.js"; |
11 | | -import { NAME as KV_CACHE_NAME } from "./kv-incremental-cache.js"; |
12 | 11 |
|
13 | 12 | const ONE_MINUTE_IN_SECONDS = 60; |
14 | 13 | const THIRTY_MINUTES_IN_SECONDS = ONE_MINUTE_IN_SECONDS * 30; |
@@ -78,20 +77,17 @@ class RegionalCache implements IncrementalCache { |
78 | 77 | private store: IncrementalCache, |
79 | 78 | private opts: Options |
80 | 79 | ) { |
81 | | - if (this.store.name === KV_CACHE_NAME) { |
82 | | - throw new Error("The KV incremental cache does not need a regional cache."); |
83 | | - } |
84 | 80 | this.name = this.store.name; |
| 81 | + // `shouldLazilyUpdateOnCacheHit` is not needed when cache purge is enabled. |
85 | 82 | this.opts.shouldLazilyUpdateOnCacheHit ??= this.opts.mode === "long-lived" && !isPurgeCacheEnabled(); |
86 | 83 | } |
87 | 84 |
|
88 | 85 | get #bypassTagCacheOnCacheHit(): boolean { |
89 | 86 | if (this.opts.bypassTagCacheOnCacheHit !== undefined) { |
90 | | - // If the bypassTagCacheOnCacheHit option is set we return that one |
91 | 87 | return this.opts.bypassTagCacheOnCacheHit; |
92 | 88 | } |
93 | 89 |
|
94 | | - // Otherwise we default to whether the automatic cache purging is enabled or not |
| 90 | + // When `bypassTagCacheOnCacheHit` is not set, we default to whether the automatic cache purging is enabled or not |
95 | 91 | return isPurgeCacheEnabled(); |
96 | 92 | } |
97 | 93 |
|
@@ -237,17 +233,7 @@ class RegionalCache implements IncrementalCache { |
237 | 233 | * a request is made to another region that has an entry stored in its regional cache. |
238 | 234 | * |
239 | 235 | * @param cache Incremental cache instance. |
240 | | - * @param opts.mode The mode to use for the regional cache. |
241 | | - * - `short-lived`: Re-use a cache entry for up to a minute after it has been retrieved. |
242 | | - * - `long-lived`: Re-use a fetch cache entry until it is revalidated (per-region), |
243 | | - * or an ISR/SSG entry for up to 30 minutes. |
244 | | - * @param opts.shouldLazilyUpdateOnCacheHit Whether the regional cache entry should be updated in |
245 | | - * the background or not when it experiences a cache hit. |
246 | | - * @param opts.defaultLongLivedTtlSec The default age to use for long-lived cache entries. |
247 | | - * When no revalidate is provided, the default age will be used. |
248 | | - * @default `THIRTY_MINUTES_IN_SECONDS` |
249 | | - * |
250 | | - * @default `false` for the `short-lived` mode, and `true` for the `long-lived` mode. |
| 236 | + * @param opts Options for the regional cache. |
251 | 237 | */ |
252 | 238 | export function withRegionalCache(cache: IncrementalCache, opts: Options) { |
253 | 239 | return new RegionalCache(cache, opts); |
|
0 commit comments