Skip to content

Commit 4a91712

Browse files
committed
update isr support
1 parent b4b3113 commit 4a91712

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

pages/cloudflare/caching.mdx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,56 @@ const config: OpenNextConfig = {
7070

7171
export default config;
7272
```
73+
74+
#### On-Demand Revalidation
75+
76+
The tag revalidation mechanism uses a [Cloudflare D1](https://developers.cloudflare.com/d1/) adapter as its backing store for information about tags, paths, and revalidation times.
77+
78+
To use on-demand revalidation, you should also follow the ISR setup steps.
79+
80+
##### 1. Create a D1 database
81+
82+
The binding name used in your app's worker is `NEXT_CACHE_D1`.
83+
84+
```jsonc
85+
// wrangler.json
86+
{
87+
// ...
88+
"d1_databases": [
89+
{
90+
"binding": "NEXT_CACHE_D1",
91+
"database_id": "<DATABASE_ID>",
92+
"database_name": "<DATABASE_NAME>"
93+
}
94+
]
95+
}
96+
```
97+
98+
##### 2. Create a table for tag revalidation
99+
100+
The default table name is `tags`. This can be configured by setting the `NEXT_CACHE_D1` environment variable to a string.
101+
102+
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.
103+
104+
```sh
105+
wrangler d1 execute NEXT_CACHE_D1 --command "CREATE TABLE IF NOT EXISTS tags (tag TEXT NOT NULL, path TEXT NOT NULL, revalidatedAt INTEGER NOT NULL, UNIQUE(tag, path) ON CONFLICT REPLACE)"
106+
```
107+
108+
##### 3. Configure the cache
109+
110+
In your project's OpenNext config, enable the KV cache and set up a queue. The `direct` queue will send a revalidation request to a page when needed, but it will not dedupe requests.
111+
112+
```ts
113+
// open-next.config.ts
114+
import tagCache from "@opennextjs/cloudflare/d1-tag-cache";
115+
116+
const config: OpenNextConfig = {
117+
default: {
118+
override: {
119+
// ...
120+
tagCache: () => tagCache,
121+
},
122+
},
123+
// ...
124+
};
125+
```

0 commit comments

Comments
 (0)