cache: 'no-store' is not refetching from scratch on fetch called
Unanswered
AM posted this in #help-forum
AMOP
I have following service:
Then this request is used in 2 server components like this:
I can see if i switch the routes sometimes data is being fetched only once and then is read from cache even with
Apart from that i have other request that is used only in 1 page:
but when user visit it once on concurent visits sometimes is not being fetch
any idea what might cause the issue?
I need to data to be refetched in RSC everytime when user opens the page
export const getTopTrends = async () => {
const response = await fetch(
api,
{
cache: 'no-store',
}
);
if (!response.ok) {
throw new Error('Failed to fetch top trends');
}
return await response.json();
};Then this request is used in 2 server components like this:
{baseUrl}/async function TableBody() {
const topTrends = await getTopTrends();
}{baseUrl}/top-trendsasync function TableBody() {
const topTrends = await getTopTrends();I can see if i switch the routes sometimes data is being fetched only once and then is read from cache even with
no-cacheApart from that i have other request that is used only in 1 page:
}baseUrl}/activities:export const getActivities = async () => {
const response = await fetch(
api
{
cache: 'no-store'
}
);
if (!response.ok) {
throw new Error('Failed to fetch activities');
}
return await response.json();
};but when user visit it once on concurent visits sometimes is not being fetch
any idea what might cause the issue?
I need to data to be refetched in RSC everytime when user opens the page
7 Replies
AMOP
Also tried with this config:
but again same requests on different routes reads from cache instead refetching
const { signal } = new AbortController();
cache: 'no-store',
signal,but again same requests on different routes reads from cache instead refetching
like:
is doing the job think so
next: {
revalidating: 0
}is doing the job think so
nah still same request on different routes is coming form the cache
AMOP
even tried with:
at some point all server components being rendered instantly and sometimes data is refetched from scratch as expected
export const fetchCache = 'force-no-store';at some point all server components being rendered instantly and sometimes data is refetched from scratch as expected
Can you prepare a minimal reproduction repository? That would help us to understand the exact issue that you're facing and come with right solution.
https://nextjs-faq.com/minimal-reproduction-repository
https://nextjs-faq.com/minimal-reproduction-repository
@Z4NR34L Can you prepare a minimal reproduction repository? That would help us to understand the exact issue that you're facing and come with right solution.
https://nextjs-faq.com/minimal-reproduction-repository
AMOP
hey @Z4NR34L ZANR3AL, here is the repo:
https://github.com/AndonMitev/nextjs-cache-min-reproducible-repo
git clone
cd nextjs-cache-min-reproducible-repo
yarn
should do the job
then play around with the navigation there 2 pages and sometimes they are loading from scratch its easy to see cuz of the suspense but sometimes there is no suspense and data is served from cache
https://github.com/AndonMitev/nextjs-cache-min-reproducible-repo
git clone
cd nextjs-cache-min-reproducible-repo
yarn
should do the job
then play around with the navigation there 2 pages and sometimes they are loading from scratch its easy to see cuz of the suspense but sometimes there is no suspense and data is served from cache