Skip to content

Commit c44df1f

Browse files
authored
1.3.0 Fixed instrumentation and clientSegmentCache (#13)
# Fixes - #10 Using Next experimental config `clientSegmentCache: true` does not cause `createBufferStringHandler` to throw `cachedData.segmentData.get is not a function` anymore - #11 Using instrumentation is now supported to call `registerInitialCache`
1 parent 9726185 commit c44df1f

File tree

10 files changed

+880
-220
lines changed

10 files changed

+880
-220
lines changed

README.md

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,43 @@
44

55
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.
66

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+
744
## Installation
845

946
To install this package along with its dependencies:
@@ -53,15 +90,39 @@ Use this:
5390

5491
```js
5592
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");
5994

6095
CacheHandler.onCreation(() => {
6196
// your usual setup
6297
});
6398

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+
}
65126
```
66127

67128
## Handlers
@@ -141,7 +202,7 @@ const createBufferStringHandler =
141202
require("@fortedigital/nextjs-cache-handler/buffer-string-decorator").default;
142203
const {
143204
Next15CacheHandler,
144-
} = require("@fortedigital/nextjs-cache-handler/next-15-cache-handler");
205+
} = require("@fortedigital/nextjs-cache-handler");
145206

146207
// Usual onCreation from @neshca/cache-handler
147208
CacheHandler.onCreation(() => {
@@ -244,7 +305,7 @@ CacheHandler.onCreation(() => {
244305
return global.cacheHandlerConfigPromise;
245306
});
246307

247-
module.exports = new Next15CacheHandler();
308+
module.exports = Next15CacheHandler;
248309
```
249310
250311
## Reference to Original Package

0 commit comments

Comments
 (0)