Skip to content

Commit e6869ea

Browse files
Fix usage of cache-handler in dev env (caching-tools#113)
- Remove unnecessary `!context.dev` condition from constructor - Update doc with `Development environment` paragraph
1 parent dab059e commit e6869ea

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

.changeset/clean-lamps-hide.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@neshca/cache-handler': patch
3+
---
4+
5+
Fix usage of `cache-handler` in dev environment

docs/examples/use-with-redis.md

+14
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,17 @@ SERVER_STARTED=1 npm run start
260260
```
261261
262262
Note that in the `build` step you don't need to set `SERVER_STARTED` environment variable.
263+
264+
## Development environment
265+
266+
When you run `next dev` command, caching in Next.js works differently. It works only for `fetch` cache for App dir pages.
267+
268+
You can identify the development environment by checking the `process.env.NODE_ENV` variable or `onCreation` parameter.
269+
270+
```js
271+
IncrementalCache.onCreation(({ dev }) => {
272+
if (dev) {
273+
// ...
274+
}
275+
});
276+
```

packages/cache-handler/src/cache-handler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class IncrementalCache implements CacheHandler {
164164
this.serverDistDir = context.serverDistDir;
165165
this.experimental = context.experimental;
166166

167-
if (!context.dev && !IncrementalCache.cache) {
167+
if (!IncrementalCache.cache) {
168168
IncrementalCache.serverDistDir = this.serverDistDir;
169169
IncrementalCache.init({ dev: context.dev, serverDistDir: this.serverDistDir });
170170
}

0 commit comments

Comments
 (0)