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
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.
);
}