Complete the code to import the Next.js caching function.
import { [1] } from 'next/cache';
The cache function from next/cache helps store data to speed up page rendering.
Complete the code to wrap a function with Next.js caching.
export const getData = [1](() => { return fetch('https://api.example.com/data'); });
Wrapping the function with cache stores its result to avoid repeated fetching.
Fix the error in the caching usage by completing the code.
const data = await [1]();You must call the cached function getData to get the cached result.
Fill the blank to create a cached fetch with revalidation time.
export const getData = cache(() => fetch('https://api.example.com/data'), { revalidate: [1] });
The revalidate time sets cache duration in seconds.
Fill the blanks to create a cached function with a revalidation.
export const getUser = cache(async (id) => {
const res = await fetch(`/api/user/$[1]`);
return res.json();
}, { revalidate: [2] });The function uses id to fetch user data, sets revalidation to 120 seconds. Next.js automatically generates unique cache keys based on the id argument.
