Next.js Discord

Discord Forum

Understanding Cache in next.js

Answered
Ping me for help posted this in #help-forum
Open in Discord
Avatar
Ping me for helpOP
I had a question. so fetch requests are cached by default, right?
Answered by Russian Blue
So if im not mistaken, after 5 mins has passed and you requested the same url, you are able to request new data, however if you request before 5 mins pass, you can only access cached data
View full answer

6 Replies

Avatar
Ping me for helpOP
and if I add next: revalidate: 300, then it'll revalidate every 5 mins, right?
for mongodb data api
    const response = await fetch(this.url + action, {
      ...options,
      next: {
        revalidate: 300,
        ...this.next,
      },

so this code will revalidate every 5 min, right?
Avatar
Russian Blue
So if im not mistaken, after 5 mins has passed and you requested the same url, you are able to request new data, however if you request before 5 mins pass, you can only access cached data
Answer
Avatar
Russian Blue
It wont automatically fetch new data because that may cause redundant requests
Avatar
Arinji
^^ Correct
You will only see the new data until you make a request to it again.