Next.js Discord

Discord Forum

Unsure what the best solution for caching is

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
Hello. I am quite new to Web Development, so my apologies as I am not sure what to do for this specific scenario and having looked around, cannot see anything that would be able to help me directly.

What I am doing:
-Fetch some data from multiple external APIs.
-Combining some of the above data for use/displaying in the website.
-(At the moment this is all being done in a route handler)

Issues:
-Even though the individual fetch requests are being cached, I still have to "rebuild/combine" the data after fetching
-Sharing this data between any component that may need it without having to re-fetch/re-build.

Apologies if these issues are not even "next" related and if there is a Discord/Forum more appropriate for this I'd appreciate some recommendations.

3 Replies

When you call your own API with fetch to get the combined data, that should be cached automatically, no?
West African LionOP
I thought so, but it doesn't seem to be ?

I tried testing it in two ways, simple console.log (it printed multiple times on the server), and also looked at network tab which also showed it multiple times. Am I misunderstanding what the caching actually does? I thought it would simply cache the Response value and not have to run any of the logic

Thank you for the reply
Best solution for caching for a new web developer is no caching at all