Mastering Fetch API and Caching in NextJS

  Рет қаралды 1,669

Taylor Lindores-Reeves

Taylor Lindores-Reeves

Күн бұрын

In this video, I guide you through a useful approach to managing the Fetch API and caching in NextJS. I demonstrate how the Fetch API by default caches data, which can be beneficial for reducing server resource load, but may also present obstacles when trying to display real-time data updates. I reveal a workaround that involves setting the cache on a global level, which allows for setting caching configurations on a per-request basis and ensures subsequent requests fetch the same data.
This method is demonstrated on a basic NextJS project that mimics an API endpoint to pull product data. Furthermore, we explore functionalities like 'revalidate', which clears the cache after a specific interval. This tutorial is suitable for those working on new and existing projects, providing a neat way to default to not caching everything and allowing caching on a request basis.
📖 Chapters:
00:00 Introduction to Fetch API with Next.js
00:21 Understanding the Default Caching in Fetch API
01:48 Demonstration: Fetch API Caching in Action
06:12 Setting Global No-Cache in Fetch API
07:24 Testing the Global No-Cache Setting
07:43 Exploring Revalidation in Fetch API
08:53 Conclusion: The Benefits of Customising Fetch API Caching
🔑 Key Takeaways
- fetchCache option globally disables caching and allows per-request control
- Next.js "revalidate" property balances caching and real-time updates
- Fetch API caches data by default but can be customised
🔗 Resources
NextJS Data Fetching, Caching, and Revalidating: nextjs.org/docs/app/building-...
NextJS Fetch Function: nextjs.org/docs/app/api-refer...
Fetch API: developer.mozilla.org/en-US/d...

Пікірлер: 5
@KadirKATIRCI
@KadirKATIRCI 5 ай бұрын
Thank you! Good explanation as i need...
@user-vm6py5gf8m
@user-vm6py5gf8m 4 ай бұрын
Thank You.Can I ask about how it would function for different users accessing server at different time.Does it revalidate at a set interval of say 60 secs or 60 secs elapsed after the user accessed the server Thank you for your explanation💥
@taylorlindoresreeves
@taylorlindoresreeves 2 ай бұрын
I think it revalidates for each specific user. It's not global in that sense.
@helciofranco6134
@helciofranco6134 Ай бұрын
Is this cache for a specific user-session or shared between every user? I'd like to understand if another user have accessed your site if he would trigger a new request or not
@taylorlindoresreeves
@taylorlindoresreeves Ай бұрын
For a REST API it’s cached globally for all users. However, if using a server action, fetch requests are not cached.
How to FETCH data from an API using JavaScript ↩️
14:17
Bro Code
Рет қаралды 108 М.
Каха заблудился в горах
00:57
К-Media
Рет қаралды 9 МЛН
ВОДА В СОЛО
00:20
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 31 МЛН
Server-side Pagination with NextJS 13 Server Actions
19:27
Taylor Lindores-Reeves
Рет қаралды 10 М.
This is why you need caching
10:03
Web Dev Cody
Рет қаралды 40 М.
Next.js App Router Caching: Explained!
25:22
Vercel
Рет қаралды 88 М.
What Next.js doesn't tell you about caching...
13:32
Marius Espejo
Рет қаралды 11 М.
The Story of Next.js
12:13
uidotdev
Рет қаралды 558 М.
Fetching and Caching data in Next.js Async Server Components
19:23
When RESTful architecture isn't enough...
21:02
Dreams of Code
Рет қаралды 260 М.
Codegen: The good, the bad and the ugly
6:37
Matt Pocock
Рет қаралды 30 М.
Каха заблудился в горах
00:57
К-Media
Рет қаралды 9 МЛН