Cache revalidate-time every 10s

DATA: 2025-08-27T18:36:21.83856



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