Consider a Next.js Server Component that fetches data but opts out of caching using export const revalidate = 0;. What happens when you refresh the page multiple times?
export const revalidate = 0; export default async function Page() { const time = new Date().toISOString(); return <p>Current time: {time}</p>; }
Think about what setting revalidate = 0 means for data fetching in Next.js.
Setting revalidate = 0 disables caching, so the data is fetched fresh on every request, updating the time each refresh.
Choose the correct way to disable caching for a Next.js Server Component.
Look for the official Next.js export that controls cache revalidation timing.
Next.js uses export const revalidate = 0; to disable caching and fetch fresh data on every request.
Review the code below. The developer expects no caching, but the page shows stale data on refresh. What is the likely cause?
export const revalidate = 0; export default async function Page() { const data = await fetch('https://api.example.com/data', { cache: 'force-cache' }).then(res => res.json()); return <p>{data.message}</p>; }
Check the fetch options and how they interact with Next.js caching.
Using cache: 'force-cache' in fetch forces caching, ignoring revalidate. To opt out, use cache: 'no-store' or omit caching options.
export const dynamic = 'force-dynamic' in Next.js?In Next.js 14+, what does setting export const dynamic = 'force-dynamic' do for a page or layout?
Consider how dynamic rendering differs from static generation.
Setting dynamic = 'force-dynamic' tells Next.js to always render the page on the server at request time, bypassing static caching.
Analyze the code below. What will the user see when the page loads and after clicking the button?
export const revalidate = 0; 'use client'; import { useState } from 'react'; function ClientCounter() { const [count, setCount] = useState(0); return <button onClick={() => setCount(count + 1)}>Count: {count}</button>; } export default function Page() { const time = new Date().toISOString(); return ( <> <p>Server time: {time}</p> <ClientCounter /> </> ); }
Think about how server and client components behave together and how caching affects server-rendered data.
The server time updates on every page load because caching is disabled. The client component manages its own state and updates count on clicks without affecting the server time.