Challenge - 5 Problems
Next.js Caching Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why does Next.js use caching for server components?
Next.js uses caching for server components mainly to:
Attempts:
2 left
💡 Hint
Think about how caching helps avoid doing the same work multiple times.
✗ Incorrect
Next.js caches server components to avoid fetching the same data repeatedly. This makes pages load faster and reduces server work.
❓ component_behavior
intermediate2:00remaining
What happens when cached data in Next.js expires?
In Next.js, when cached data for a page expires, the framework will:
Attempts:
2 left
💡 Hint
Consider how caching systems keep data fresh.
✗ Incorrect
Next.js uses cache expiration to know when to fetch new data. When expired, it fetches fresh data and updates the cache automatically.
📝 Syntax
advanced2:30remaining
Which Next.js code snippet correctly enables caching for a server component?
Select the code snippet that properly uses Next.js caching for a server component fetching data.
NextJS
import { cache } from 'react'; const fetchData = cache(async () => { const res = await fetch('https://api.example.com/data'); return res.json(); }); export default async function Page() { const data = await fetchData(); return <div>{data.message}</div>; }
Attempts:
2 left
💡 Hint
Look for the official React cache() function usage.
✗ Incorrect
Next.js recommends using React's cache() to memoize async data fetching in server components. This avoids repeated fetches.
🔧 Debug
advanced2:30remaining
Why does this Next.js server component fetch data on every request despite caching?
Given this code, why is data fetched every time instead of cached?
import { cache } from 'react';
async function getData() {
return await fetch('https://api.example.com/data').then(res => res.json());
}
const cachedGetData = cache(getData);
export default async function Page() {
const data = await getData();
return
{data.title}
;
}Attempts:
2 left
💡 Hint
Check which function is actually called inside the component.
✗ Incorrect
The component calls getData() directly, ignoring the cached version cachedGetData. So caching does not happen.
❓ lifecycle
expert3:00remaining
How does Next.js caching interact with Incremental Static Regeneration (ISR)?
In Next.js, when using ISR with a revalidate time, caching works by:
Attempts:
2 left
💡 Hint
Think about how ISR balances caching and freshness.
✗ Incorrect
ISR caches static pages and serves them instantly. When the revalidate time passes, Next.js regenerates the page in the background for future requests.