You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Upgraded nextjs in example project
* Updated package dependencies
* Ensure cache handler is used in dev mode
* Merge branch 'master' into next16
* Bump
* Merge dev and version bump
* Ran migrations from next 16 docs
* Fixed new lint issues
* Fixed package json
* Adjusted .env and added readme comment
* Reworked example project (#160)
* Reworked examples
* Updated readme
* F
* Added new examples (#161)
* Extra examples
* Layout changes
* Added unstable cache example
* Version bump
* Next 16 updateTag and cache profiles examples (incremental cache handler) (#162)
* Added revalidate profile example
* Added updateTag example
* Added compatibility matrix
* Readme improvements (#163)
* Added compatibility matrix
* Readme improvements
* F
* F
* Merge fixes and readme update
* Fix/next16 rsc issues (#199)
* Added repro steps example
* F
* Ensures correct RSC data handling by prioritizing prefetch and fallback to page data.
* Bumped versions
* 3.0.0
* Updated readme
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
1
+
# Next.js Cache Handler Examples
2
+
3
+
This example application demonstrates various Next.js caching functionalities using the Redis cache handler. It provides a comprehensive UI to explore and test different caching strategies.
2
4
3
5
## Getting Started
4
6
5
-
First, run the development server:
7
+
First, install dependencies:
6
8
7
9
```bash
8
10
npm i
9
-
npm run dev
10
11
```
11
12
12
-
Or run build and run production server:
13
+
### Important: Development vs Production Mode
14
+
15
+
**Next.js does not use the cache handler in development mode.** This is a Next.js limitation - caching is intentionally disabled in dev mode for faster hot reloading and to ensure developers always see fresh data.
16
+
17
+
To test caching functionality, you must use **production mode**:
13
18
14
19
```bash
15
-
npm i
16
20
npm run build
17
21
npm run start
18
22
```
19
23
24
+
For development (without caching):
25
+
26
+
```bash
27
+
npm run dev
28
+
```
29
+
20
30
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
21
31
22
-
Modify `.env` file if you need to.
32
+
## Configuration
33
+
34
+
Modify the `.env` file if you need to configure Redis connection settings. The default Redis URL is used if not specified.
23
35
24
36
### Redis Client Configuration
25
37
@@ -32,10 +44,214 @@ This allows you to test the `ioredisAdapter` functionality.
32
44
33
45
## Examples
34
46
35
-
-http://localhost:3000
36
-
-http://localhost:3000/fetch-example
37
-
-http://localhost:3000/static-params-test/cache
47
+
The application includes several examples demonstrating different Next.js caching features:
48
+
49
+
### 1. Home Page (`/`)
50
+
51
+
Overview page listing all available examples with descriptions and features.
52
+
53
+
### 2. Default Cache (`/examples/default-cache`)
54
+
55
+
Demonstrates the default fetch caching behavior with `force-cache`.
# Revalidate by tag (POST) - defaults to 'max' profile
224
+
curl -X POST http://localhost:3000/api/revalidate \
225
+
-H "Content-Type: application/json" \
226
+
-d '{"tag": "futurama"}'
227
+
228
+
# Revalidate by tag with specific profile (POST)
229
+
curl -X POST http://localhost:3000/api/revalidate \
230
+
-H "Content-Type: application/json" \
231
+
-d '{"tag": "futurama", "cacheLife": "days"}'
232
+
233
+
# Revalidate by path (POST)
234
+
curl -X POST http://localhost:3000/api/revalidate \
235
+
-H "Content-Type: application/json" \
236
+
-d '{"path": "/examples/default-cache"}'
237
+
```
238
+
239
+
## Cache Handler
240
+
241
+
This example uses a custom Redis cache handler configured in `cache-handler.mjs`. The handler supports:
242
+
243
+
- Redis string-based caching
244
+
- Local LRU fallback
245
+
- Composite caching strategy
246
+
- Tag-based cache invalidation
247
+
248
+
**Note:** The cache handler only works in production mode. In development mode, Next.js bypasses the cache handler entirely. You'll see a warning message in the console: `"Next.js does not use the cache in development mode. Use production mode to enable caching."`
0 commit comments