rsnext/examples/cache-handler-redis
David Sa 7725047c89
update cache handler version in example (#65330)
### What?
Update the cache-handler package to the latest and changed logic for
opting out of caching during build.

### Why?
The current implementation in the cache-handler-redis example requires
an environment variable check for `REDIS_AVAILABLE` to determine if the
server has already started in order to opt out of caching during build.
This update leverages the `NEXT_PHASE` environment variable instead.

### How?
This updates the environment variable check to leverage the `NEXT_PHASE`
variable so a user doesn't have to manage a new environment variable.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-05-13 14:58:55 -07:00
..
app chore(examples): use default prettier for examples/templates (#60530) 2024-01-11 16:01:44 -07:00
public Add a self-hosted shared cache example (#58000) 2023-11-09 14:29:11 +00:00
.gitignore Add a self-hosted shared cache example (#58000) 2023-11-09 14:29:11 +00:00
cache-handler.js update cache handler version in example (#65330) 2024-05-13 14:58:55 -07:00
docker-compose.yml chore(examples): use default prettier for examples/templates (#60530) 2024-01-11 16:01:44 -07:00
next.config.js Update Redis Cache example with stabilized API (#60800) 2024-01-21 02:40:54 +00:00
package.json update cache handler version in example (#65330) 2024-05-13 14:58:55 -07:00
README.md Update Redis Cache example with stabilized API (#60800) 2024-01-21 02:40:54 +00:00
tsconfig.json Add a self-hosted shared cache example (#58000) 2023-11-09 14:29:11 +00:00

Next.js Redis Cache Integration Example

This example is tailored for self-hosted setups and demonstrates how to use Redis as a shared cache. It is built on the principles of the @neshca/cache-handler package, which replaces the default Next.js cache handler and adds advanced caching features.

Check out this repository that contains a comprehensive setup for Kubernetes.

How to use

Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:


npx create-next-app --example cache-handler-redis cache-handler-redis-app
yarn create next-app --example cache-handler-redis cache-handler-redis-app
pnpm create next-app --example cache-handler-redis cache-handler-redis-app

Once you have installed the dependencies, you can begin running the example Redis Stack server by using the following command:

docker-compose up -d

Then, build and start the Next.js app as usual.

Documentation

For detailed information on configuration and usage, please refer to our comprehensive Documentation ↗.

Key Features and Considerations

  • Handlers: The @neshca/cache-handler package includes Handlers for seamless integration with Redis.

  • Create Your Own Handlers: Take a look at Custom Redis Handler and use it as a basis to create your own handler.

  • Redis Server Setup: Ensure your Redis server is running and properly configured before starting your Next.js application.

  • Configure Redis Credentials: Update the cache-handler-redis* files with your Redis credentials. Connection details can be found here.

  • Building Without Redis: To build the app without connecting to Redis use conditions inside onCreation callback. Check the documentation for more details.

Development and Production Considerations

  • The provided docker-compose.yml is intended for local development. For production deployment, refer to the official Redis installation and management guidelines.

  • Clearing Redis Cache: To clear the Redis cache, use RedisInsight Workbench or the following CLI command:

    docker exec -it redis-stack redis-cli
    127.0.0.1:6379> flushall
    OK