Course map
Stage 1: App Router Foundations
Stage 2: The Rendering Model
Stage 3: Data, Caching and Mutations
Stage 4: Full-Stack Next.js
Stage 5: Production and Specialization

Part 10 / Topic 3 of 6

cacheLife profiles — this install's real numbers, and a genuine surprise

Reading this install's own config, not assuming: node_modules/next/dist/server/config-shared.js defines the preset cacheLife profiles that ship with every app using Cache Components (seconds shown):

Profile stale revalidate expire
default 300 (5 min) 900 (15 min) INFINITE_CACHE (0xfffffffe ≈ 136 years, capped at this install's expireTime config of 1 year when it reaches an actual response header — see the going-deeper note)
seconds 30 1 60
minutes 300 60 3600
hours 300 3600 86400
days 300 86400 604800
weeks 300 604800 2592000
max 300 2592000 31536000

Swapping getDailyStats's cacheLife('hours') for cacheLife('seconds') (kept as a second function, getDailyStatsFast, so both exist side by side) looked, at first, like it should just mean "refreshes more often." Building it exactly like section 2's page — no <Suspense> — reproduced a real build error:

$ npm run build
...
Error: Route "/mandi/stats/fast": Next.js encountered runtime data during prerendering.

`cookies()`, `headers()`, `params`, or `searchParams` accessed outside of `<Suspense>` prevents the route from being prerendered...

The error message's wording is almost the same family as section 1's genuinely-uncached case — and node_modules/next/dist/docs/01-app/03-api-reference/04-functions/cacheLife.md's own "Prerendering behavior" section explains exactly why: "revalidate of 0, or expire under 5 minutes: excluded from prerenders, becoming a 'dynamic hole' resolved at request time." 'seconds''s expire is 60 seconds — under 5 minutes — so Cache Components refuses to bake it into the static shell at all, cached directive or not. The fix is the same one section 1 already needed:

// harness/app/mandi/stats/fast/page.tsx
async function FastStats() {
  const stats = await getDailyStatsFast();
  return <>{/* ... */}</>;
}

export default function StatsFastPage() {
  return (
    <main>
      <Suspense fallback={<p id="fallback">Loading…</p>}>
        <FastStats />
      </Suspense>
    </main>
  );
}

With <Suspense> in place, the build succeeds, and the real build table shows the difference between the two stats pages directly:

├ ○ /mandi/stats                               1h      1d
├ ◐ /mandi/stats/fast

/mandi/stats is fully static (○) with a Revalidate/Expire column; /mandi/stats/fast is a Partial Prerender (◐) — a static shell around a genuine request-time hole, headers confirming it the same way section 1's did (x-nextjs-postponed: 1, Cache-Control: private, no-cache, no-store). Hitting it repeatedly, 1.5 seconds apart, over a real next start:

$ for i in 1 2 3 4; do curl -s http://localhost:PORT/mandi/stats/fast | grep -o 'computed-at">[^<]*'; sleep 1.5; done
computed-at">2026-12-01T11:08:10.732Z
computed-at">2026-12-01T11:08:12.898Z
computed-at">2026-12-01T11:08:15.068Z
computed-at">2026-12-01T11:08:17.244Z

A new value every single time at this 1.5-second spacing — revalidate: 1 means almost every request past that one second window triggers a fresh computation, which is exactly the real-time-data use case 'seconds' exists for (the docs name "stock prices, live scores"). Full file: examples/04-stats-fast-page.tsx.

🔍 Going deeper — the default profile's "never" isn't infinite in a response header: top-categories/page.tsx (section 4) calls no cacheLife at all, so it gets the implicit default profile. Its real response header reads Cache-Control: s-maxage=900, stale-while-revalidate=31535100. 900 is default's 15-minute revalidate, exactly as the table above says. But 31535100 is not derived from default's raw expire (INFINITE_CACHE, 0xfffffffe ≈ 136 years) — it's 31536000 - 900, where 31536000 is exactly one year in seconds. This install's global config-shared.js default, expireTime: 31536000, is a separate, top-level cap on how long a CDN is told it may hold a "never expires" entry — confirmed by reading that exact field in the same config file the cacheLife table above came from. The build's own route table independently agrees: it shows top-categories's Expire column as 1y, not some astronomically large number. Don't assume default's "infinite" expire shows up as infinite anywhere a real HTTP client can see — it's capped before it ever leaves the server.

Done here? The practice set for Part 10 — including the solutions — is on the part page.

Search the guide