|
3 | 3 | # @fortedigital/nextjs-cache-handler |
4 | 4 |
|
5 | 5 | A caching utility built originally on top of [`@neshca/cache-handler`](https://www.npmjs.com/package/@neshca/cache-handler), providing additional cache handlers for specialized use cases with a focus on Redis-based caching. |
6 | | -Starting from version `2.0.0`, this package no longer depends on `@neshca/cache-handler` and is fully maintained and compatible with Next.js 15 and onwards. |
| 6 | + |
| 7 | +**Version compatibility:** |
| 8 | +- Version `3.x.x`: Next.js 16+ (with "use cache" and cacheComponents support) |
| 9 | +- Version `2.x.x`: Next.js 15+ (legacy) |
| 10 | +- Version `1.x.x`: Next.js 14 and earlier (deprecated) |
| 11 | + |
| 12 | +Starting from version `2.0.0`, this package no longer depends on `@neshca/cache-handler` and is fully maintained independently. |
7 | 13 |
|
8 | 14 | ## Documentation |
9 | 15 |
|
10 | 16 | The documentation at [@neshca/cache-handler - caching-tools.github.io/next-shared-cache](https://caching-tools.github.io/next-shared-cache) is mostly still relevant, though some details may be outdated. New features or relevant changes are described below. |
11 | 17 |
|
12 | 18 | ## Migration |
13 | 19 |
|
| 20 | +- [2.x.x → ^3.x.x (Next.js 16)](#nextjs-16-migration) |
14 | 21 | - [1.x.x → ^2.x.x](https://github.com/fortedigital/nextjs-cache-handler/blob/master/docs/migration/1_x_x__2_x_x.md) |
15 | 22 | - [1.2.x -> ^1.3.x](https://github.com/fortedigital/nextjs-cache-handler/blob/master/docs/migration/1_2_x__1_3_x.md) |
16 | 23 |
|
17 | | -## Installation |
| 24 | +### Next.js 16 Migration |
18 | 25 |
|
19 | | -`npm i @fortedigital/nextjs-cache-handler` |
| 26 | +Version 3.0.0 adds full support for Next.js 16 with the following key changes: |
| 27 | + |
| 28 | +**Breaking Changes:** |
| 29 | +- Requires Next.js 16.0.0 or later |
| 30 | +- The cache handler API now supports the optional `durations` parameter in `revalidateTag(tag, durations?)` |
| 31 | + |
| 32 | +**App Router Changes:** |
| 33 | +When using `cacheComponents: true` in Next.js 16, you must replace `export const revalidate` with the `"use cache"` directive: |
| 34 | + |
| 35 | +```tsx |
| 36 | +// ❌ Old (Next.js 15 / incompatible with cacheComponents) |
| 37 | +export const revalidate = 3600; |
| 38 | +export default async function Page() { |
| 39 | + return <div>{new Date().toISOString()}</div>; |
| 40 | +} |
20 | 41 |
|
21 | | -If upgrading from Next 14 or earlier, **flush your Redis cache** before running new version of the application locally and on your hosted environments. **Cache formats between Next 14 and 15 are incompatible**. |
| 42 | +// ✅ New (Next.js 16) |
| 43 | +"use cache"; |
| 44 | +export default async function Page() { |
| 45 | + return <div>{new Date().toISOString()}</div>; |
| 46 | +} |
| 47 | +``` |
22 | 48 |
|
23 | | -## Next 15 Support |
| 49 | +**Important Notes:** |
| 50 | +- The custom `cacheHandler` continues to work for ISR, fetch caching, and route handlers |
| 51 | +- The new "use cache" directive is managed separately by Next.js and does not use the custom cache handler |
| 52 | +- Pages Router (`getStaticProps` with `revalidate`) continues to work unchanged |
| 53 | +- Flush your Redis cache when upgrading from Next.js 15 to Next.js 16 |
24 | 54 |
|
25 | | -The original `@neshca/cache-handler` package does not support Next.js 15. |
| 55 | +## Installation |
26 | 56 |
|
27 | | -Prior to 2.0.0, this package provided wrappers and enhancements to allow using `@neshca/cache-handler` with Next.js 15. |
28 | | -From version 2.0.0 onward, `@fortedigital/nextjs-cache-handler` is a standalone solution with no dependency on `@neshca/cache-handler` and is fully compatible with Next.js 15 and [redis 5](https://www.npmjs.com/package/redis). |
| 57 | +`npm i @fortedigital/nextjs-cache-handler` |
| 58 | + |
| 59 | +If upgrading from Next 14 or earlier, **flush your Redis cache** before running new version of the application locally and on your hosted environments. **Cache formats between Next.js versions may be incompatible**. |
| 60 | + |
| 61 | +## Next.js 16 Support |
| 62 | + |
| 63 | +Version 3.0.0 provides full support for Next.js 16, including: |
| 64 | +- ✅ Cache Components and `"use cache"` directive |
| 65 | +- ✅ Updated `revalidateTag` API with optional durations parameter |
| 66 | +- ✅ Turbopack compatibility |
| 67 | +- ✅ Async request APIs (`params`, `searchParams`) |
| 68 | +- ✅ ISR and fetch caching (traditional cache handler) |
| 69 | +- ✅ Playwright e2e tests for caching behavior |
| 70 | + |
| 71 | +**Configuration for Next.js 16:** |
| 72 | +```ts |
| 73 | +// next.config.ts |
| 74 | +const nextConfig = { |
| 75 | + cacheHandler: require.resolve('./cache-handler.mjs'), |
| 76 | + cacheMaxMemorySize: 0, |
| 77 | + cacheComponents: true, // Enable Cache Components |
| 78 | +}; |
| 79 | +``` |
29 | 80 |
|
30 | | -We aim to keep up with new Next.js releases and will introduce major changes with appropriate version bumps. |
| 81 | +We aim to keep the package version in sync with major Next.js releases and will introduce breaking changes with appropriate version bumps. |
31 | 82 |
|
32 | 83 | ### Swapping from `@neshca/cache-handler` |
33 | 84 |
|
|
0 commit comments