Skip to content

Commit 9a746d2

Browse files
authored
fix: detection of cache purge (#881)
1 parent 23b67ce commit 9a746d2

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

.changeset/tricky-monkeys-wear.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+
fix: detection of cache purge

examples/e2e/app-router/open-next.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import r2IncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cac
33
import shardedTagCache from "@opennextjs/cloudflare/overrides/tag-cache/do-sharded-tag-cache";
44
import doQueue from "@opennextjs/cloudflare/overrides/queue/do-queue";
55
import queueCache from "@opennextjs/cloudflare/overrides/queue/queue-cache";
6-
import { purgeCache } from "@opennextjs/cloudflare/overrides/cache-purge/index";
76

87
export default defineCloudflareConfig({
98
incrementalCache: r2IncrementalCache,

packages/cloudflare/src/api/overrides/cache-purge/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ export const purgeCache = ({ type = "direct" }: PurgeOptions) => {
3131
},
3232
} satisfies CDNInvalidationHandler;
3333
};
34+
35+
export default purgeCache;

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,13 @@ class RegionalCache implements IncrementalCache {
8181
}
8282

8383
// Otherwise we default to whether the automatic cache purging is enabled or not
84-
const hasAutomaticCachePurging = !!getCloudflareContext().env.NEXT_CACHE_DO_PURGE;
85-
return hasAutomaticCachePurging;
84+
return this.#hasAutomaticCachePurging;
85+
}
86+
87+
get #hasAutomaticCachePurging() {
88+
const cdnInvalidation = globalThis.openNextConfig.default?.override?.cdnInvalidation;
89+
90+
return cdnInvalidation !== undefined && cdnInvalidation !== "dummy";
8691
}
8792

8893
async get<CacheType extends CacheEntryType = "cache">(

0 commit comments

Comments
 (0)