Next.js Discord

Discord Forum

How to manage dynamic cached data

Unanswered
Egyptian Mau posted this in #help-forum
Open in Discord
Egyptian MauOP
Hello i'm building an app in nextjs to learn the framework

My app will fetch data from external api to show it to my users (core of the app)

Lets says my fetched data from exetrnal api is a list of 500 chiropractor, as user if you see yourself in the list, you can customise your profile by adding a phone number, a profile picture, your price etc. So your profile in the list of 500 will be customised while other chiropractors will maybe just have their names with 0 customisation

But this list will be refreshed every 24hours

So there will be a situation where Monday you see yourself with your customised profile in the list, refresh list, Tuesday you are out of the 500th because someone is 1 rank ahead of you, refresh list, Wednesday you are back on the list but still have your customised profile


How can i manage this situation ? Should i put everything in my database (list + user customisation) and update the list's "customised profile" based on if the user is in the list.

Or i should interact with my cached data and if my user (database) is in the list of cached data, i update the cached data with his customised profile ?


sorry for my bad explanation

3 Replies

Barbary Lion
Inside NextJS the fetch function has added options like caching. You can also add a revalidate option for 24 hours.

https://nextjs.org/docs/app/api-reference/functions/fetch
You can also generate a page with static data, with a 24 hour revalidate option.
I suggest you take time to read the NextJS docs, it is very well explained