Skip to content

Commit e6938a0

Browse files
authored
allow using a regional cache with KV (#1105)
1 parent 0ca5747 commit e6938a0

2 files changed

Lines changed: 8 additions & 17 deletions

File tree

.changeset/tidy-symbols-wonder.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
allow using a regional cache with KV

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88

99
import { getCloudflareContext } from "../../cloudflare-context.js";
1010
import { debugCache, FALLBACK_BUILD_ID, IncrementalCacheEntry, isPurgeCacheEnabled } from "../internal.js";
11-
import { NAME as KV_CACHE_NAME } from "./kv-incremental-cache.js";
1211

1312
const ONE_MINUTE_IN_SECONDS = 60;
1413
const THIRTY_MINUTES_IN_SECONDS = ONE_MINUTE_IN_SECONDS * 30;
@@ -78,20 +77,17 @@ class RegionalCache implements IncrementalCache {
7877
private store: IncrementalCache,
7978
private opts: Options
8079
) {
81-
if (this.store.name === KV_CACHE_NAME) {
82-
throw new Error("The KV incremental cache does not need a regional cache.");
83-
}
8480
this.name = this.store.name;
81+
// `shouldLazilyUpdateOnCacheHit` is not needed when cache purge is enabled.
8582
this.opts.shouldLazilyUpdateOnCacheHit ??= this.opts.mode === "long-lived" && !isPurgeCacheEnabled();
8683
}
8784

8885
get #bypassTagCacheOnCacheHit(): boolean {
8986
if (this.opts.bypassTagCacheOnCacheHit !== undefined) {
90-
// If the bypassTagCacheOnCacheHit option is set we return that one
9187
return this.opts.bypassTagCacheOnCacheHit;
9288
}
9389

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
9591
return isPurgeCacheEnabled();
9692
}
9793

@@ -237,17 +233,7 @@ class RegionalCache implements IncrementalCache {
237233
* a request is made to another region that has an entry stored in its regional cache.
238234
*
239235
* @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.
251237
*/
252238
export function withRegionalCache(cache: IncrementalCache, opts: Options) {
253239
return new RegionalCache(cache, opts);

0 commit comments

Comments
 (0)