#How does fetch cache work?

4 messages · Page 1 of 1 (latest)

devout finch
#

I don't understand fetch caching. When I write in a server component

const getData = async () => {
  const data = await fetch('http://worldtimeapi.org/api/timezone/Asia/Taipei')
  return data.json()
}

export default async function Home() {
  const data = await getData()
  const time = data.datetime

I thought every time I run npm run build I will get a new time. Instead I always get the same value.
Where is this being cached and how can i inspect this cache.

hexed sapphire
#

Hey,
When you make a new build, it keeps the .next/cache folder and reuse it

#

If you want new cache, delete this folder between your builds 🙂

#

(or a add next: { revalidate: X } inside your fetch func)