"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Next.js Caching Issues With Fetching Data

Next.js Caching Issues With Fetching Data

Published on 2024-08-01
Browse:897

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

Release Statement This article is reproduced at: https://dev.to/rahulkumarhavitmsi/nextjs-caching-issues-with-fetching-data-180a?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3