🎉 Version 1.8.0 is out! Use shared cache for the Next.js Pages API routes and getServerSideProps with neshClassicCache
Usage guidesOn-demand revalidation

On-demand revalidation

Next.js provides a way to revalidate a page or a result of a fetch call on demand. @neshca/cache-handler supports this feature with one limitation: revalidatePath only works for the Pages Router.

Usage

Pages Router

The Pages Router supports only the response.revalidate(path).

See Using On-Demand Revalidation ↗ in the Next.js documentation.

response.revalidate(path) caveat

Calling response.revalidate(path) will synchronously call getStaticProps and render the page with a given path. Then it will revalidate the cache for this page. If you want to revalidate multiple paths at once, you need to call response.revalidate(path) multiple times.

App Router

The App Router supports both revalidatePath and revalidateTag functions. These functions will remove the cache values from the store.

See On-demand Revalidation ↗ in the Next.js documentation.

revalidatePath caveat

The revalidatePath function works differently from the response.revalidate(path) and revalidateTag functions. It does not revalidate the cached fetch result immediately. Instead, it marks the cache as revalidated and the next request will revalidate the cache.

If you are creating a custom cache Handler, you need to manually mark the cache as revalidated in Handler’s revalidateTag method. Later in the Handler’s get method, you must check if the cache is revalidated and return null if necessary. See Custom Redis strings example