33[ ![ npm version] ( https://img.shields.io/npm/v/@trieb.work/nextjs-turbo-redis-cache.svg )] ( https://www.npmjs.com/package/@trieb.work/nextjs-turbo-redis-cache )
44![ Turbo redis cache image] ( https://github.com/user-attachments/assets/98e0dfd9-f38a-42ad-a355-9843740cc2d6 )
55
6-
7-
8-
96The ultimate Redis caching solution for Next.js. Built for production-ready, large-scale projects, it delivers unparalleled performance and efficiency with features tailored for high-traffic applications. This package has been created after extensibly testing the @neshca package and finding several major issues with it.
107
118Key Features:
@@ -29,21 +26,6 @@ Tested versions are:
2926
3027Currently PPR, 'use cache', cacheLife and cacheTag are not tested. Use these operations with caution and your own risk.
3128
32- ## Available Options (needs Option B of getting started)
33-
34- | Option | Description | Default Value |
35- | ---------------------- | ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
36- | database | Redis database number to use. Uses DB 0 for production, DB 1 otherwise | ` process.env.VERCEL_ENV === 'production' ? 0 : 1 ` |
37- | keyPrefix | Prefix added to all Redis keys | ` process.env.VERCEL_URL \|\| 'UNDEFINED_URL_' ` |
38- | sharedTagsKey | Key used to store shared tags hash map in Redis | ` '__sharedTags__' ` |
39- | timeoutMs | Timeout in milliseconds for Redis operations | ` 5000 ` |
40- | revalidateTagQuerySize | Number of entries to query in one batch during full sync of shared tags hash map | ` 250 ` |
41- | avgResyncIntervalMs | Average interval in milliseconds between tag map full re-syncs | ` 3600000 ` (1 hour) |
42- | redisGetDeduplication | Enable deduplication of Redis get requests via internal in-memory cache. | ` true ` |
43- | inMemoryCachingTime | Time in milliseconds to cache Redis get results in memory. Set this to 0 to disable in-memory caching completely. | ` 10000 ` |
44- | defaultStaleAge | Default stale age in seconds for cached items | ` 1209600 ` (14 days) |
45- | estimateExpireAge | Function to calculate expire age (redis TTL value) from stale age | Production: ` staleAge * 2 ` <br > Other: ` staleAge * 1.2 ` |
46-
4729## Getting started
4830
4931### Enable redis key-space notifications for Expire and Evict events
@@ -76,6 +58,8 @@ const nextConfig = {
7658}
7759```
7860
61+ Make sure to set either REDIS_URL or REDISHOST and REDISPORT environment variables.
62+
7963### Option B: create a wrapper file to change options
8064
8165create new file ` customized-cache-handler.js ` in your project root and add the following code:
@@ -129,6 +113,22 @@ const nextConfig = {
129113
130114A working example of above can be found in the ` test/integration/next-app-customized ` folder.
131115
116+ ## Available Options
117+
118+ | Option | Description | Default Value |
119+ | ---------------------- | ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
120+ | redis_url | Redis connection url | ` process.env.REDIS_URL? process.env.REDIS_URL : process.env.REDISHOST ? redis://${process.env.REDISHOST}:${process.env.REDISPORT} : 'redis://localhost:6379' ` |
121+ | database | Redis database number to use. Uses DB 0 for production, DB 1 otherwise | ` process.env.VERCEL_ENV === 'production' ? 0 : 1 ` |
122+ | keyPrefix | Prefix added to all Redis keys | ` process.env.VERCEL_URL \|\| 'UNDEFINED_URL_' ` |
123+ | sharedTagsKey | Key used to store shared tags hash map in Redis | ` '__sharedTags__' ` |
124+ | timeoutMs | Timeout in milliseconds for Redis operations | ` 5000 ` |
125+ | revalidateTagQuerySize | Number of entries to query in one batch during full sync of shared tags hash map | ` 250 ` |
126+ | avgResyncIntervalMs | Average interval in milliseconds between tag map full re-syncs | ` 3600000 ` (1 hour) |
127+ | redisGetDeduplication | Enable deduplication of Redis get requests via internal in-memory cache. | ` true ` |
128+ | inMemoryCachingTime | Time in milliseconds to cache Redis get results in memory. Set this to 0 to disable in-memory caching completely. | ` 10000 ` |
129+ | defaultStaleAge | Default stale age in seconds for cached items | ` 1209600 ` (14 days) |
130+ | estimateExpireAge | Function to calculate expire age (redis TTL value) from stale age | Production: ` staleAge * 2 ` <br > Other: ` staleAge * 1.2 ` |
131+
132132## Consistency of Redis and this caching implementation
133133
134134To understand consistency levels of this caching implementation we first have to understand the consistency of redis itself:
@@ -170,7 +170,9 @@ By accepting and tolerating this eventual consistency, the performance of the ca
170170
171171## Testing
172172
173- To run all tests you can use the following command:
173+ Run ` pnpm run-dev-server ` to start the nextjs integration test project.
174+
175+ To run all tests you can use the following command in a second terminal:
174176
175177``` bash
176178pnpm test
0 commit comments