mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
When a prerendered and deployed route handler is revalidated, we can not rely on having a cache handler that does in-memory caching. So we need to provide a prerender resume data cache (RDC) instead, to ensure that the revalidation doesn't fail with the following error: ``` Error: Dynamic server usage: Route / couldn't be rendered statically because it used IO that was not cached. ``` Route handlers are never resumed, so it's counter-intuitive to use an RDC for this scenario. However, we need the data cache to store cached results in memory during the prospective prerender, so that they can be retrieved during the final prerender within microtasks. In a follow-up, we should replace the `prerenderResumeDataCache` and `renderResumeDataCache` with a single `dataCache` property that is conceptually not tied to resuming, and also avoids the unnecessary complexity of using a mutable and an immutable resume data cache. closes NAR-350
22 lines
437 B
TypeScript
22 lines
437 B
TypeScript
import { setTimeout } from 'timers/promises'
|
|
|
|
async function getCachedDate() {
|
|
'use cache'
|
|
|
|
// Simulate I/O latency.
|
|
await setTimeout(200)
|
|
|
|
return new Date().toISOString()
|
|
}
|
|
|
|
export async function GET() {
|
|
const date1 = await getCachedDate()
|
|
const date2 = await getCachedDate()
|
|
|
|
const response = JSON.stringify({ date1, date2 })
|
|
|
|
return new Response(response, {
|
|
headers: { 'content-type': 'application/json' },
|
|
})
|
|
}
|