next.js/test/e2e/app-dir/use-cache/app/(partially-static)/cache-life-with-dynamic/page.tsx
page.tsx37 lines716 B
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>
    </>
  )
}
Quest for Codev2.0.0
/
SIGN IN