Next.js Discord

Discord Forum

force-dynamic vs cache:no store

Unanswered
NuclearMonkey posted this in #help-forum
Open in Discord
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>
  );
}

5 Replies

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 no-store it only needs normal refresh to get new data no need for hard refresh
I think these links should help:
this cache shit is confusing to me too