Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Next.js cache debugging tool.
NextJS
import { [1] } from 'next/cache';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent import like 'cacheDebugger'.
Confusing hook names like 'useCache'.
✗ Incorrect
The unstable_cache function is the official Next.js caching tool import.
2fill in blank
mediumComplete the code to wrap a function with Next.js cache debugging.
NextJS
const cachedFunction = [1](() => { return fetch('/api/data'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent function like 'cacheDebugger'.
Trying to use hooks like 'useCache' outside React components.
✗ Incorrect
The unstable_cache function wraps your function to enable caching.
3fill in blank
hardFix the error in the cache debugging function call.
NextJS
const data = await unstable_cache(() => fetch('/api/data'), { [1]: 60 });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect option names like 'timeout' or 'cacheTime'.
Confusing cache options with React state options.
✗ Incorrect
The correct option to set cache duration is revalidate in seconds.
4fill in blank
hardFill both blanks to create a cache key part and set revalidate time.
NextJS
const cachedData = unstable_cache(fetchData, { keyParts: ["[1]"], revalidate: [2] }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers as keys or strings as revalidate values.
Mixing up cache key and revalidate values.
✗ Incorrect
Use a descriptive string like 'user-data' as the key part and set revalidate to 60 seconds.
5fill in blank
hardFill all three blanks to define a cached fetch with keyParts, revalidate, and tags.
NextJS
const cachedFetch = unstable_cache(fetchData, { keyParts: ["[1]"], revalidate: [2], tags: ["[3]"] }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect types for options.
Forgetting to add tags.
✗ Incorrect
Use 'api-fetch' as the key part, set revalidate to 30 seconds, and use 'api-tag' as the tag.