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
{{ message }}
Repository navigation
Commit 270d42b
Browse filesBrowse the repository at this point in the historyBrowse files
fix(cache): batch CDN tag purges per request and log purge failures (#4074)
* fix(cache): batch CDN tag purges per request and log purge failures
revalidatePath/revalidateTag/updateTag sent one CDN adapter call per API
call, and a failed edge purge rejected the request drain. On Workers Cache,
purges share a 5-per-minute account budget, so an autosaving Server Action
with several revalidatePath calls hit error 1134 and returned a 500 even
though its write had committed.
- Inside a Server Action or Route Handler, defer the CDN purge to the
request drain and send one adapter call per cacheLife profile, matching
Next.js' executeRevalidates. The data cache is still invalidated per call.
- Log CDN adapter failures instead of failing the request; the data cache
is already invalidated, so the edge just stays stale until it expires.
- Split Workers Cache purges into chunks of 100 tags, Cloudflare's
per-request cap.
Fixes#4071
* fix(route-handlers): flush CDN purges queued by completed bodies and regeneration
A completed Route Handler body can call revalidateTag() after the
handler's eager drain, so drain again once completion finishes. Stale
route regeneration ran the handler in the render phase, so it skipped
batching; run it in the route-handler phase a live request uses.
* fix(cache): keep deferred CDN purges from being stranded
- after() callbacks run once the response has closed, past the request's
last drain, so they purge immediately instead of deferring.
- Drain what a Route Handler body queued before it failed during
completion, keeping the body error as the response error.
- Settle every Workers Cache purge chunk before reporting a failure so no
started purge is left un-awaited.
This setup is fast when an entry is present at the edge, but Workers Cache is distributed rather than one globally shared cache. A response cached in one region may still miss in another. Tiered caching can reduce this duplication, but without a durable response store a regional miss or eviction can require another render. The KV data cache is also eventually consistent.
232
232
233
+
`revalidatePath()` and `revalidateTag()` purge the edge by tag. [Workers Cache purges](https://developers.cloudflare.com/workers/cache/purge/) use Cloudflare's Free-tier purge limits, which every Worker in the account shares. As in Next.js, vinext sends one batched purge per cacheLife profile at the end of a Server Action or Route Handler, not one per call. If a purge fails, for example because the rate limit is reached, vinext logs the error and the action still succeeds: the data cache is already invalidated, but edge-cached responses for those tags stay stale until they expire. A route that only needs the client to refetch dynamic data can call `refresh()`, which doesn't purge.
234
+
233
235
Use `createWorkersCacheConfig()` to configure the response entrypoints and version metadata, and add the KV binding for the data adapter:
0 commit comments