|
4 | 4 |
|
5 | 5 | This package extends the functionality of [`@neshca/cache-handler`](https://www.npmjs.com/package/@neshca/cache-handler) by providing additional cache handlers for specialized use cases, specifically for Redis-based caching solutions. The original `@neshca/cache-handler` offers a robust caching API for Next.js applications, and this package introduces two new handlers for managing Redis cache with different expiration strategies and tag-based revalidation.
|
6 | 6 |
|
| 7 | + |
| 8 | +## Migration |
| 9 | + |
| 10 | +### 1.2.x -> 1.3.x |
| 11 | + |
| 12 | +#### cache-handler |
| 13 | +1.2.x |
| 14 | +``` |
| 15 | +const { Next15CacheHandler } = require("@fortedigital/nextjs-cache-handler/next-15-cache-handler"); |
| 16 | +module.exports = new Next15CacheHandler(); |
| 17 | +``` |
| 18 | + |
| 19 | +1.3.x |
| 20 | +``` |
| 21 | +const { Next15CacheHandler } = require("@fortedigital/nextjs-cache-handler"); |
| 22 | +module.exports = Next15CacheHandler; |
| 23 | +``` |
| 24 | + |
| 25 | +#### instrumentation |
| 26 | +1.2.x |
| 27 | +``` |
| 28 | +if (process.env.NEXT_RUNTIME === "nodejs") { |
| 29 | + const { registerInitialCache } = await import('@neshca/cache-handler/instrumentation') |
| 30 | + const CacheHandler = (await import("./cache-handler.js")).default; |
| 31 | + await registerInitialCache(CacheHandler); |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +1.3.x |
| 36 | +``` |
| 37 | +if (process.env.NEXT_RUNTIME === "nodejs") { |
| 38 | + const { registerInitialCache } = await import("@fortedigital/nextjs-cache-handler/instrumentation"); |
| 39 | + const CacheHandler = (await import("./cache-handler.js")).default; |
| 40 | + await registerInitialCache(CacheHandler); |
| 41 | +} |
| 42 | +``` |
| 43 | + |
7 | 44 | ## Installation
|
8 | 45 |
|
9 | 46 | To install this package along with its dependencies:
|
@@ -53,15 +90,39 @@ Use this:
|
53 | 90 |
|
54 | 91 | ```js
|
55 | 92 | const { CacheHandler } = require("@neshca/cache-handler");
|
56 |
| -const { |
57 |
| - Next15CacheHandler, |
58 |
| -} = require("@fortedigital/nextjs-cache-handler/next-15-cache-handler"); |
| 93 | +const { Next15CacheHandler } = require("@fortedigital/nextjs-cache-handler"); |
59 | 94 |
|
60 | 95 | CacheHandler.onCreation(() => {
|
61 | 96 | // your usual setup
|
62 | 97 | });
|
63 | 98 |
|
64 |
| -module.exports = new Next15CacheHandler(); |
| 99 | +module.exports = Next15CacheHandler; |
| 100 | +``` |
| 101 | + |
| 102 | +### Instrumentation |
| 103 | + |
| 104 | +Instead of: |
| 105 | + |
| 106 | +```js |
| 107 | +export async function register() { |
| 108 | + if (process.env.NEXT_RUNTIME === 'nodejs') { |
| 109 | + const { registerInitialCache } = await import('@neshca/cache-handler/instrumentation'); |
| 110 | + const CacheHandler = (await import('../cache-handler.mjs')).default; |
| 111 | + await registerInitialCache(CacheHandler); |
| 112 | + } |
| 113 | +} |
| 114 | +``` |
| 115 | + |
| 116 | +Use this: |
| 117 | + |
| 118 | +```js |
| 119 | +export async function register() { |
| 120 | + if (process.env.NEXT_RUNTIME === 'nodejs') { |
| 121 | + const { registerInitialCache } = await import('@fortedigital/nextjs-cache-handler/instrumentation'); |
| 122 | + const CacheHandler = (await import('../cache-handler.mjs')).default; |
| 123 | + await registerInitialCache(CacheHandler); |
| 124 | + } |
| 125 | +} |
65 | 126 | ```
|
66 | 127 |
|
67 | 128 | ## Handlers
|
@@ -141,7 +202,7 @@ const createBufferStringHandler =
|
141 | 202 | require("@fortedigital/nextjs-cache-handler/buffer-string-decorator").default;
|
142 | 203 | const {
|
143 | 204 | Next15CacheHandler,
|
144 |
| -} = require("@fortedigital/nextjs-cache-handler/next-15-cache-handler"); |
| 205 | +} = require("@fortedigital/nextjs-cache-handler"); |
145 | 206 |
|
146 | 207 | // Usual onCreation from @neshca/cache-handler
|
147 | 208 | CacheHandler.onCreation(() => {
|
@@ -244,7 +305,7 @@ CacheHandler.onCreation(() => {
|
244 | 305 | return global.cacheHandlerConfigPromise;
|
245 | 306 | });
|
246 | 307 |
|
247 |
| -module.exports = new Next15CacheHandler(); |
| 308 | +module.exports = Next15CacheHandler; |
248 | 309 | ```
|
249 | 310 |
|
250 | 311 | ## Reference to Original Package
|
|
0 commit comments