export default async function Page() { const data = await fetch('https://api.example.com/data', { cache: 'force-cache' }).then(res => res.json()); return <pre>{JSON.stringify(data)}</pre>; }
Using cache: 'force-cache' tells Next.js to serve cached data if it exists, without revalidating. So stale data is shown until cache is cleared or invalidated.
The browser's Network tab shows if the response is served from cache (304 Not Modified) or fetched fresh (200 OK). This helps identify caching issues.
Setting next: { revalidate: 10 } tells Next.js to cache the response and revalidate it every 10 seconds. The 'cache' option is optional here.
'use client'; import { useState, useEffect } from 'react'; export default function ClientComponent() { const [data, setData] = useState(null); useEffect(() => { fetch('/api/data', { cache: 'force-cache' }) .then(res => res.json()) .then(setData); }, []); return <div>{data ? data.value : 'Loading...'}</div>; }
Using cache: 'force-cache' means the fetch returns cached data even if the API changed, so the component shows stale data after re-render.
revalidate: 60. After updating content in the CMS, users still see old data for several minutes. Which is the most accurate explanation?ISR updates static pages only when a request comes after the revalidate interval. Until then, users see the cached static page.
