Suat
Suat

Reputation: 63

Roadmap for Server Side Rendering Caching in Next Js

I created a Next JS Project and I created REST API with PHP.

I have a website that is constantly dealing with api requests. And I want to cache some locations. I don't want it to constantly request Api.

As an example, all data on My Homepage comes from the REST API.

And it is a bad situation that every time the visitor enters the homepage, they request the REST API again.

For example, I want to clear the cache every 1 hour and request it again. For any data extraction How can I do this with Next Js. What kind of path should I follow?

Thank you. Best regards.

Upvotes: 0

Views: 7241

Answers (1)

Yilmaz
Yilmaz

Reputation: 49182

you can have 3 approaches:

  • set up graphql. I think this is the best approach for large scale applications. All graphql packages automatically handles the caching.

  • you can set up redux with reselect library. reselect library handles the caching for redux. You fetch

  • There is a nice package swr which is created by next.js-vercel team. Stale-While-Revalidate. it first returns the data from cache(stale), then sends the fetch request, and finally comes with the updated data again. SWR is backend agnostic, you can use it to retrieve data from any server that supports HTTP requests.

Upvotes: 1

Related Questions