Complete the code to fetch fresh data by disabling cache in Next.js fetch.
const data = await fetch('/api/data', { cache: '[1]' });
Using 'no-store' tells Next.js to fetch fresh data every time, disabling cache.
Complete the code to revalidate cached data every 60 seconds in Next.js.
const data = await fetch('/api/data', { next: { revalidate: [1] } });
Setting revalidate: 60 tells Next.js to refresh the cache every 60 seconds.
Fix the error in the code to correctly revalidate cache after 10 seconds.
const data = await fetch('/api/data', { next: { revalidate: [1] } });
The revalidate value must be a number representing seconds, not a string.
Fill both blanks to create a cache key and set stale-while-revalidate header.
export async function GET() {
const cacheKey = [1];
return new Response('data', {
headers: { 'Cache-Control': 'max-age=0, [2]=60' }
});
}The cache key is a string like 'user-data'. The header 'stale-while-revalidate=60' allows serving stale data while revalidating.
Fill all three blanks to create a Next.js fetch with cache disabled, revalidate after 30 seconds, and use a custom cache key.
const data = await fetch('/api/data', { cache: [1], next: { revalidate: [2] }, headers: { 'x-cache-key': [3] } });
Use 'no-store' to disable cache, 30 seconds for revalidation, and a string like 'custom-key-123' as a custom cache key header.