import Link from 'next/link'; import { cacheLife, cacheTag, revalidateTag } from 'next/cache'; import { Suspense } from 'react'; async function getCacheLifeSample() { 'use cache'; // Very short timings for manual testing. cacheLife({ stale: 2, revalidate: 4, expire: 10, }); cacheTag('cache-lab:cachelife-short'); return { createdAt: Date.now(), random: Math.random(), }; } async function triggerRevalidateTag() { 'use server'; revalidateTag('cache-lab:cachelife-short', { expire: 1 }); } async function CachedDataPanel() { const data = await getCacheLifeSample(); return (
createdAt
{data.createdAt}
random
{data.random}
cacheLife config
{'{ stale: 2, revalidate: 4, expire: 10 }'}
); } export default function CacheLifeShortPage() { return (
← Back to Cache Lab

cacheLife: short timings

This uses cacheLife with short durations so you can observe stale / revalidate / expire behavior quickly.

Loading cached content… } >

Expected: reload a few times. Within a couple seconds, the cached value may become stale; after revalidate, a fresh value should appear.

This page deliberately puts the async work behind{' '} {''} to avoid the "Blocking Route" warning.

); }