How can I cache the server side fetch request? I am running the same fetch thousands of times this means, once for each page, but the only parameter is the locale.
export const getStaticProps: GetStaticProps = async ({ locale }) => {
const accountManager = await getAccountManager(locale);
return {
props: {
accountManager: accountManager
},
revalidate: 120,
};
};
export async function getAccountManagerByLocale(
tld = 'com'
): Promise<AccountManager> {
const res = await fetch(
process.env.NEXT_PUBLIC_CRM_API_URL + '/account-manager/?locale=' + tld,
{
headers: {
accept: 'application/json, text/plain, */*',
'accept-language': 'en',
},
}
);
const accountManagersList = await res.json();
return accountManagersList[0];
}
P.S.:
- Nextjs fetch polyfill seems to ignore the Cache-Policy header
- React-Query seems too big for an ecommerce (since the client only fetch data for products when filtering) , I'm hardcoding an account managers json on the server for now only to not increase the bundle size that much