You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `direct` mode for the queue is intended for debugging purposes and is not recommended for use in production. We are actively working on a solution that will be suitable for production.
77
+
</Callout>
78
+
79
+
#### On-Demand Revalidation
80
+
81
+
The tag revalidation mechanism uses a [Cloudflare D1](https://developers.cloudflare.com/d1/) database as its backing store for information about tags, paths, and revalidation times.
82
+
83
+
To use on-demand revalidation, you should also follow the [ISR setup steps](#incremental-static-regeneration-isr).
84
+
85
+
<Callout>
86
+
If your app **only** uses the pages router, it does not need to have a tag cache and should skip this step.
87
+
</Callout>
88
+
89
+
##### 1. Create a D1 database
90
+
91
+
The binding name used in your app's worker is `NEXT_CACHE_D1`.
92
+
93
+
```jsonc
94
+
// wrangler.json
95
+
{
96
+
// ...
97
+
"d1_databases": [
98
+
{
99
+
"binding":"NEXT_CACHE_D1",
100
+
"database_id":"<DATABASE_ID>",
101
+
"database_name":"<DATABASE_NAME>",
102
+
},
103
+
],
104
+
}
105
+
```
106
+
107
+
##### 2. Create tables for tag revalidations
108
+
109
+
The D1 tag cache requires two tables; one that keeps a record of the tag/path mappings, and another that tracks revalidation times.
110
+
111
+
For the tag mappings, the default table name is `tags`, and can be configured by setting the `NEXT_CACHE_D1_TAGS_TABLE` environment variable to a string.
112
+
113
+
For the revalidation times, the default table name is `revalidations` and can be configured by setting the `NEXT_CACHE_D1_REVALIDATIONS_TABLE` environment variable to a string.
114
+
115
+
Wrangler can be used to create a table with it's [execute](https://developers.cloudflare.com/d1/wrangler-commands/#d1-execute) option. Ensure that you create a table for both your local dev database and your remote database.
116
+
117
+
```sh
118
+
wrangler d1 execute NEXT_CACHE_D1 --command "CREATE TABLE IF NOT EXISTS tags (tag TEXT NOT NULL, path TEXT NOT NULL, UNIQUE(tag, path) ON CONFLICT REPLACE)"
119
+
wrangler d1 execute NEXT_CACHE_D1 --command "CREATE TABLE IF NOT EXISTS revalidations (tag TEXT NOT NULL, revalidatedAt INTEGER NOT NULL, UNIQUE(tag) ON CONFLICT REPLACE)"
120
+
```
121
+
122
+
##### 3. Configure the cache
123
+
124
+
In your project's OpenNext config, enable the KV cache and set up a queue. The queue will send a revalidation request to a page when needed, but it will not dedupe requests.
In order for the cache to be properly initialised with the build-time revalidation data, you need to setup a command that runs as part of your deploy step.
148
+
149
+
OpenNext will generate an SQL file during the build that can be used to setup your D1 database.
Copy file name to clipboardExpand all lines: pages/cloudflare/index.mdx
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -53,10 +53,12 @@ We will update the list as we progress towards releasing 1.0.
53
53
-[x][Image optimization](https://nextjs.org/docs/app/building-your-application/optimizing/images) (you can integrate Cloudflare Images with Next.js by following [this guide](https://developers.cloudflare.com/images/transform-images/integrate-with-frameworks/))
0 commit comments