Skip to content

Commit e928d67

Browse files
committed
[cloudflare] add docs for the durable objects Queue
1 parent a705ca0 commit e928d67

1 file changed

Lines changed: 40 additions & 11 deletions

File tree

pages/cloudflare/caching.mdx

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { Callout } from "nextra/components";
55

66
`@opennextjs/cloudflare` supports [caching](https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data).
77

8-
By default, all `fetch()` subrequests made in your Next.js app are cached. Refer to the [Next.js documentation](https://nextjs.org/docs/app/building-your-application/caching#opting-out-1) for information about how to disable caching for an individual subrequest, or for an entire route.
8+
In Next.js 14, all `fetch()` requests made in your app are cached by default. However, in Next.js 15, `fetch()` requests are not cached by default. Refer to the [Next.js documentation](https://nextjs.org/docs/app/building-your-application/caching#opting-out-1) for information about how to enable or disable caching for an individual request, or for an entire route.
99

10-
[The cache persists across deployments](https://nextjs.org/docs/app/building-your-application/caching#data-cache). You are responsible for revalidating/purging this cache.
10+
[The cache is unique per build (prefixed by BUILD_ID) so caches are not reused between deployments](https://nextjs.org/docs/app/building-your-application/caching#data-cache). You are responsible for revalidating/purging the cache for a specific build or if you keep the same build ID.
1111

1212
Next.js primes the cache at build time. The build time values are serverd by the [Workers Assets](https://developers.cloudflare.com/workers/static-assets/).
1313

@@ -57,28 +57,57 @@ The binding name used in your app's worker is `NEXT_CACHE_WORKERS_KV`.
5757

5858
In your project's OpenNext config, enable the KV cache and set up a queue.
5959

60-
The memory queue will send revalidation requests to a page when needed, and offers support for de-duplicating requests on a per-isolate basis. There might still be duplicate requests under high traffic or across regions.
61-
62-
<Callout type="warning">
63-
The memory queue provided by `@opennextjs/cloudflare` is not fully suitable for production deployments, you
64-
can use it at your own risk!
65-
</Callout>
60+
The Durable Object Queue will send revalidation requests to a page when needed, and offers support for de-duplicating requests.
61+
By default there will be a maximum of 10 instance of the Durables Object Queue and they can each process up to 5 requests in parallel.(For up to 50 ISR revalidations in parallel)
6662

6763
```ts
6864
// open-next.config.ts
6965
import { defineCloudflareConfig } from "@opennextjs/cloudflare";
7066
import kvIncrementalCache from "@opennextjs/cloudflare/kv-cache";
71-
import memoryQueue from "@opennextjs/cloudflare/memory-queue";
67+
import doQueue from "@opennextjs/cloudflare/durable-queue";
7268

7369
export default defineCloudflareConfig({
7470
incrementalCache: kvIncrementalCache,
75-
queue: memoryQueue,
71+
queue: doQueue,
7672
});
7773
```
7874

75+
You will also need to add some binding to your `wrangler.jsonc` file.
76+
77+
```jsonc
78+
"durable_objects": {
79+
"bindings": [
80+
{
81+
"name": "NEXT_CACHE_REVALIDATION_DURABLE_OBJECT",
82+
"class_name": "DurableObjectQueueHandler"
83+
}
84+
]
85+
},
86+
"migrations": [
87+
{
88+
"tag": "v1",
89+
"new_sqlite_classes": ["DurableObjectQueueHandler"]
90+
}
91+
],
92+
```
93+
94+
You can customize the behaviors of the queue with environment variables:
95+
- The max number of durable workers that can be created (MAX_REVALIDATE_CONCURRENCY)
96+
- The max number of revalidations that can be processed by an instance of durable worker at the same time (MAX_REVALIDATION_BY_DURABLE_OBJECT)
97+
- The max time in milliseconds that a revalidation can take before being considered as failed (REVALIDATION_TIMEOUT_MS)
98+
- The amount of time after which a revalidation will be attempted again if it failed. If it fails again it will exponentially back off until it reaches the max retry interval (REVALIDATION_RETRY_INTERVAL_MS)
99+
- The maximum number of attempts that can be made to revalidate a path (MAX_REVALIDATION_ATTEMPTS)
100+
101+
79102
<Callout>
80-
The `direct` mode for the queue is intended for debugging purposes and is not recommended for use in
103+
There is 2 additional modes that you can use for the queue `direct` and the memory queue
104+
105+
- The memory queue will dedupe request but only on a per isolate basis. It is not fully suitable for production deployments, you
106+
can use it at your own risk!
107+
108+
- The `direct` mode for the queue is intended for debugging purposes and is not recommended for use in
81109
production. We are actively working on a solution that will be suitable for production.
110+
82111
</Callout>
83112

84113
#### On-Demand Revalidation

0 commit comments

Comments
 (0)