Next.js Discord

Discord Forum

export const fetchCache = 'default-cache'; VERCEL deployment

Unanswered
wackjalr posted this in #help-forum
Open in Discord
I have a problem where my next application deployed on vercel is not storing anything in the data cache after I have used a dynamic function (getServerSession). I read the docs and it looks like I can override this by setting the below in my layout. This works on my local dev server and I'm a little bit stuck.

export const fetchCache = 'default-cache';

I have api calls that don't require any authentication and it would be good to be able to cache these... seems like a pretty common use case. Am I missing anything?

13 Replies

Would you be able to share some code how your page and layout looks like (the fetching stuff)?
@wackjalr ?
I am using apollo client. This is obviously a test page using a custom api but should be able to swap a datetime one or something similar
If I don't use the getServerSession then it works as expected..
@B33fb0n3
yea, when you fetch data from a third party, you are not able to cache it, if you use their methods to call the request. You are able to cache it a little with the react cache function, to memoize data request. You can also use the unstable_cache, but it's experimental. You can read more about it here: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#fetching-data-on-the-server-with-third-party-libraries
@wackjalr ?
@B33fb0n3 I don’t think that is the case. Apollo client uses fetch under the hood as described here. It’s working locally. I assume it’s something to do with vercel….

https://www.apollographql.com/blog/apollo-client/next-js/how-to-use-apollo-client-with-next-js-13/
I think to fetch stuff like this with the fetch method (see screenshot) you need to write it like that. I have the same problem with amplify graphql. The graphql endpoint itself is just a url and I can easily fetch it via fetch. But I can also use the sdk to fetch stuff. If I use the sdk (like you do here) it's like you using a third party. So the caching won't be automatically @wackjalr
https://ibb.co/PF5Pdfh
@wackjalr ?
That’s because amplify uses axios not fetch. As mentioned this is to do with the vercel data cache more than next behaviour as it works locally
I think axios itself works with fetch in the background