mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
37 lines
716 B
TypeScript
37 lines
716 B
TypeScript
import { cacheLife } from 'next/cache'
|
|
import { connection } from 'next/server'
|
|
import { Suspense } from 'react'
|
|
|
|
async function getCachedRandom() {
|
|
'use cache'
|
|
cacheLife('frequent')
|
|
return Math.random()
|
|
}
|
|
|
|
async function DynamicCache() {
|
|
'use cache'
|
|
cacheLife({ revalidate: 99, expire: 299, stale: 18 })
|
|
return <p id="y">{new Date().toISOString()}</p>
|
|
}
|
|
|
|
async function Dynamic() {
|
|
await connection()
|
|
return null
|
|
}
|
|
|
|
export default async function Page() {
|
|
const x = await getCachedRandom()
|
|
|
|
return (
|
|
<>
|
|
<p id="x">{x}</p>
|
|
<Suspense fallback={<p id="y">Loading...</p>}>
|
|
<DynamicCache />
|
|
</Suspense>
|
|
<Suspense>
|
|
<Dynamic />
|
|
</Suspense>
|
|
</>
|
|
)
|
|
}
|