Skip to content

No need to lazy refresh the regional cache when cache purge is used #879

@vicb

Description

@vicb

When i.e. "long-lived" R2 cache is used, the regional cache is refreshed from R2 after cache hits:

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:

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

/cc @conico974 @dario-piotrowicz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions