-
Notifications
You must be signed in to change notification settings - Fork 70
Description
When i.e. "long-lived" R2 cache is used, the regional cache is refreshed from R2 after cache hits:
opennextjs-cloudflare/packages/cloudflare/src/api/overrides/incremental-cache/regional-cache.ts
Lines 103 to 111 in 3be30a4
getCloudflareContext().ctx.waitUntil( | |
this.store.get(key, cacheType).then(async (rawEntry) => { | |
const { value, lastModified } = rawEntry ?? {}; | |
if (value && typeof lastModified === "number") { | |
await this.putToCache({ key, cacheType, entry: { value, lastModified } }); | |
} | |
}) | |
); |
This is needed when cache purge is enabled.
That is shouldLazilyUpdateOnCacheHit
should default to false when cache purge is in use.
Note that in the source code, we already check if the cache purge is enabled via:
opennextjs-cloudflare/packages/cloudflare/src/api/overrides/incremental-cache/regional-cache.ts
Line 84 in 3be30a4
const hasAutomaticCachePurging = !!getCloudflareContext().env.NEXT_CACHE_DO_PURGE; |
But this check is not correct. Having a DO binding does not mean that purge is enabled:
- there could be a DO but no cache purge override configured - in this case we assume that cache purge is used but it is not
- there could be no DO and a direct cache purge configure - in this case we assume that cache purge is not used but it actually is
A more robust way to detect if cache purge is enabled would be via globalThis.openNextConfig