This PR includes documentation that preps for v2 docs (but doesn't introduce new docs). _Note: The number of file changes in the PR is due to find-and-replace within the `references` which is unavoidable. Let me know if I should move it to another PR._ ## Changes - Change Medusa version in base OAS used for v2. - Fix to docblock generator related to not catching all path parameters. - Added typedoc plugin that generates ER Diagrams, which will be used specifically for data model references in commerce modules. - Changed OAS tool to output references in `www/apps/api-reference/specs-v2` directory when the `--v2` option is used. - Added a version switcher to the API reference to switch between V1 and V2. This switcher is enabled by an environment variable, so it won't be visible/usable at the moment. - Upgraded docusaurus to v3.0.1 - Added new Vale rules to ensure correct spelling of Medusa Admin and module names. - Added new components to the `docs-ui` package that will be used in future documentation changes.
2.9 KiB
description
| description |
|---|
| In this document, you’ll learn about the Redis cache module and how you can install it in your Medusa backend. |
Redis Cache Module
In this document, you’ll learn about the Redis cache module and how you can install it in your Medusa backend.
Overview
Medusa’s modular architecture allows developers to extend or replace the logic used for caching. You can create a custom module, or you can use the modules Medusa provides.
One of these modules is the Redis Module. This module allows you to utilize Redis for the caching functionality. This document will you guide you through installing the Redis Module.
Prerequisites
Medusa Backend
It’s assumed you already have a Medusa backend installed. If not, you can learn how to install it by following this guide.
Redis
You must have Redis installed and configured in your Medusa backend. You can learn how to install it from the Redis documentation.
Step 1: Install the Module
In the root directory of your Medusa backend, install the Redis cache module with the following command:
npm install @medusajs/cache-redis
Step 2: Add Environment Variable
The Redis cache module requires a connection URL to Redis as part of its options. If you don’t already have an environment variable set for a Redis URL, make sure to add one:
CACHE_REDIS_URL=<YOUR_REDIS_URL>
Where <YOUR_REDIS_URL> is a connection URL to your Redis instance.
Step 3: Add Configuration
In medusa-config.js, add the following to the exported object:
module.exports = {
// ...
modules: {
// ...
cacheService: {
resolve: "@medusajs/cache-redis",
options: {
redisUrl: process.env.CACHE_REDIS_URL,
ttl: 30,
},
},
},
}
This registers the Redis cache module as the main cache service to use. In the options, you pass redisUrl with the value being the environment variable you set.
You also pass the option ttl. This means time-to-live, and it indicates the number of seconds an item can live in the cache before it’s removed. If it's set to 0, the module will skip adding the items to the cache.
Other available options include:
redisOptions: an object containing options for the Redis instance. You can learn about available options in io-redis’s documentation. By default, it’s an empty object.namespace: a string used to prefix event keys. By default, it'smedusa.
Step 4: Test Module
To test the module, run the following command to start the Medusa backend:
npx medusa develop
If the module was installed successfully, you should see the following message in the logs:
Connection to Redis in module 'cache-redis' established