Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/good-eyes-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/cloudflare": patch
---

Log cache purge errors as errors
3 changes: 2 additions & 1 deletion examples/e2e/app-router/open-next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export default defineCloudflareConfig({
},
},
}),
cachePurge: purgeCache({ type: "durableObject" }),
// `CACHE_PURGE_ZONE_ID` and `CACHE_PURGE_API_TOKEN` are required to enable cache purge
// cachePurge: purgeCache({ type: "durableObject" }),
enableCacheInterception: true,
queue: queueCache(doQueue),
});
6 changes: 3 additions & 3 deletions packages/cloudflare/src/api/cloudflare-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ declare global {
// This can be safely used if you don't use an eventually consistent incremental cache (i.e. R2 without the regional cache for example)
NEXT_CACHE_DO_QUEUE_DISABLE_SQLITE?: string;

// Below are the optional env variables for purging the cache
// Durable Object namespace to use for the durable object cache purge
// Below are the env variables to use for purging the cache
// Durable Object namespace to use for the durable object cache purge (not needed in direct mode)
NEXT_CACHE_DO_PURGE?: DurableObjectNamespace<BucketCachePurge>;
// The amount of time in seconds that the cache purge will wait before purging the cache
// The amount of time in seconds that the cache purge will wait before purging the cache (not needed in direct mode)
NEXT_CACHE_DO_PURGE_BUFFER_TIME_IN_SECONDS?: string;
// The zone ID to use for the cache purge https://developers.cloudflare.com/fundamentals/setup/find-account-and-zone-ids/
CACHE_PURGE_ZONE_ID?: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/cloudflare/src/api/overrides/cache-purge/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { error } from "@opennextjs/aws/adapters/logger.js";
import type { CDNInvalidationHandler } from "@opennextjs/aws/types/overrides.js";

import { getCloudflareContext } from "../../cloudflare-context.js";
Expand All @@ -19,7 +20,7 @@ export const purgeCache = ({ type = "direct" }: PurgeOptions) => {
} else {
const durableObject = env.NEXT_CACHE_DO_PURGE;
if (!durableObject) {
debugCache("cdnInvalidation", "No durable object found. Skipping cache purge.");
error("Purge cache: NEXT_CACHE_DO_PURGE not found. Skipping cache purge.");
return;
}
const id = durableObject.idFromName("cache-purge");
Expand Down
10 changes: 5 additions & 5 deletions packages/cloudflare/src/api/overrides/internal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createHash } from "node:crypto";

import { error } from "@opennextjs/aws/adapters/logger.js";
import type { CacheEntryType, CacheValue } from "@opennextjs/aws/types/overrides.js";

import { getCloudflareContext } from "../cloudflare-context.js";
Expand Down Expand Up @@ -50,7 +51,7 @@ export async function purgeCacheByTags(tags: string[]) {
export async function internalPurgeCacheByTags(env: CloudflareEnv, tags: string[]) {
if (!env.CACHE_PURGE_ZONE_ID && !env.CACHE_PURGE_API_TOKEN) {
// THIS IS A NO-OP
debugCache("purgeCacheByTags", "No cache zone ID or API token provided. Skipping cache purge.");
error("No cache zone ID or API token provided. Skipping cache purge.");
return "missing-credentials";
}

Expand All @@ -71,17 +72,16 @@ export async function internalPurgeCacheByTags(env: CloudflareEnv, tags: string[
);
if (response.status === 429) {
// Rate limit exceeded
debugCache("purgeCacheByTags", "Rate limit exceeded. Skipping cache purge.");
error("purgeCacheByTags: Rate limit exceeded. Skipping cache purge.");
return "rate-limit-exceeded";
}
const bodyResponse = (await response.json()) as {
success: boolean;
errors: Array<{ code: number; message: string }>;
};
if (!bodyResponse.success) {
debugCache(
"purgeCacheByTags",
"Cache purge failed. Errors:",
error(
"purgeCacheByTags: Cache purge failed. Errors:",
bodyResponse.errors.map((error) => `${error.code}: ${error.message}`)
);
return "purge-failed";
Expand Down