async function getWorldTime() {
const endpoint =
'https://timeapi.io/api/time/current/zone?timeZone=Asia%2FKuching';
const currentCache = await CheckCacheStatus(endpoint);
const res = await fetch(
'https://timeapi.io/api/time/current/zone?timeZone=Asia%2FKuching',
{
next: {
tags: ['worldtime-cache-revalidate'],
revalidate: 10,
},
}
);
if (res.ok) {
const data = await res.json();
const encodedData = Buffer.from(JSON.stringify(data)).toString('base64');
return {
dateTime: data.dateTime,
cache: encodedData === currentCache ? 'HIT' : 'MISS',
};
}
return null;
}
export default async function CacheRevalidate() {
const data = await getWorldTime();
if (!data) {
return <div>loading...</div>;
}
return (
<div>
Cache reavalidate 10s: {data.dateTime}. CACHE: {data.cache}
</div>
);
}