Caching and revalidating in Next.js 15

What is Caching?

You surely have heard about caching. Browsers have cache, some apps have cache, you are probably using some function to “clear cache” to speed up you phone, but what is caching, exactly?

Caching is a process of storing data in a temporary storage for future quicker access.

What does it mean for you, a Next.js web developer?

Let’s say you’ve made a cooking recipes app. When user enters a page with recipes list, you fetch() it for them from some API.

And this particular API? It’s very slow. 🐌

Like, very, very slow – it takes 10 seconds to respond, and during this time your user sees nothing but “Loading…” Sounds like awful user experience, right?

The recipes aren’t changing that often, and the new ones are being added every few days – that’s where caching comes into play. You don’t have to fetch() the data every time user enters the list. You can cache it, and serve the list straight from your app, omitting the terribly slow API. User gets recipes instantly, and you don’t even have to make the API call, saving your monthly 1000 calls from the free plan limit. 😅

It's just one of the caching mechanisms available in Next.js to make your app lightning fast. We’ll go over them below.