Maison > interface Web > js tutoriel > le corps du texte

Next.js Caching Issues With Fetching Data

王林
Libérer: 2024-07-29 10:01:25
original
162 Les gens l'ont consulté

Next.js Caching Issues With Fetching Data

Introduction

Common caching issue in Next.js while building a application is default caching behaviour of Next.js that leads to frustration for so many developer. In so many case the caching helping to speed up page loads and reduce server load by storing copies of resources.
However, it can sometimes lead to outdated content displayed, which can be problematic for dynamic application like blog feed where new blog displayed when added.

Opting out of Data Caching

Next.js extends the native Web fetch() API to allow each request on the server to set its own persistent caching semantics.

To opt out of caching for individual fetch requests, you can set the cache option in fetch to 'no-store'. This will fetch data dynamically, on every request.

export default async function Page() {

  const dynamicData = await fetch(`https://...`, { cache: 'no-store' })
  const data = await dynamicData.json()
}
Copier après la connexion

This will help override the default caching behaviour of Next.js

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

source:dev.to
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!