首頁 > web前端 > js教程 > 主體

Next.js Caching Issues With Fetching Data

王林
發布: 2024-07-29 10:01:25
原創
162 人瀏覽過

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()
}
登入後複製

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

以上是Next.js Caching Issues With Fetching Data的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:dev.to
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!