Challenge - 5 Problems
Cache Debugging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
Understanding cache behavior in Next.js Server Components
Consider a Next.js Server Component that fetches data with caching enabled. What will be the output if the cache is stale but the component is rendered again?
NextJS
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>; }
Attempts:
2 left
💡 Hint
Remember that 'force-cache' uses cached data if available, even if stale.
✗ Incorrect
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.
🔧 Debug
intermediate2:00remaining
Identifying cache invalidation issues in Next.js
You notice your Next.js app does not update data after deployment despite changes on the API. Which cache debugging tool helps you verify if the cache is causing this?
Attempts:
2 left
💡 Hint
Look for HTTP status codes indicating cache hits or misses.
✗ Incorrect
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.
📝 Syntax
advanced2:00remaining
Correct usage of cache control in Next.js fetch
Which option correctly sets the fetch cache to revalidate every 10 seconds in a Next.js Server Component?
Attempts:
2 left
💡 Hint
The 'next' option controls revalidation timing.
✗ Incorrect
Setting next: { revalidate: 10 } tells Next.js to cache the response and revalidate it every 10 seconds. The 'cache' option is optional here.
❓ state_output
advanced2:00remaining
Effect of cache on component state updates
In a Next.js app, a client component fetches data from an API and caches it. If the API data changes but the cache is not invalidated, what will the component display after a user interaction that triggers a re-render?
NextJS
'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>; }
Attempts:
2 left
💡 Hint
Consider how 'force-cache' affects fetch results on re-render.
✗ Incorrect
Using cache: 'force-cache' means the fetch returns cached data even if the API changed, so the component shows stale data after re-render.
🧠 Conceptual
expert3:00remaining
Diagnosing cache-related stale data in Next.js with ISR
You deployed a Next.js app using Incremental Static Regeneration (ISR) with
revalidate: 60. After updating content in the CMS, users still see old data for several minutes. Which is the most accurate explanation?Attempts:
2 left
💡 Hint
Think about how ISR timing works with user requests.
✗ Incorrect
ISR updates static pages only when a request comes after the revalidate interval. Until then, users see the cached static page.