force-dynamic vs cache:no store
Unanswered
NuclearMonkey posted this in #help-forum
export const dynamic = 'force-dynamic';
export default async function Home() {
const response = await fetch(
`https://www.randomnumberapi.com/api/v1.0/random`
);
const data = await response.json();
return (
<div>
<p>{Math.random()}</p>
<p>{data[0]}</p>
</div>
);
}vs
export default async function Home() {
const response = await fetch(
`https://www.randomnumberapi.com/api/v1.0/random`,
{ cache: 'no-store' }
);
const data = await response.json();
return (
<div>
<p>{Math.random()}</p>
<p>{data[0]}</p>
</div>
);
}in the force dynamic version when I refresh the data received from the API doesn't get the new version even I refresh many times, it need a hard refresh to get the new data. While using the
cache:no-store it only needs normal refresh to get new data no need for hard refreshthe code I'm running is in dev build, the docs did say that using force-dynamic is the same as Setting the option of every fetch() request in a layout or page to { cache: 'no-store', next: { revalidate: 0 } }. so the 1st block of code is technically the same as the 2nd block. I'm still confused
24 Replies
@NuclearMonkey
Looks normal
cant access
oh
try now @NuclearMonkey
oh wait i see, i was seeing the first number
oh
did it also happen in your sandbox?
@NuclearMonkey did it also happen in your sandbox?
#discussions check their for a soln/workaround
to be honest I'm really confused about this
in the docs
that it will use no-store if use put force-dynamic
putting
export const revalidate = 0; instead of export const dynamic = 'force-dynamic'; will work though