npm.io
2.22.7 • Published 4d ago

@medusajs/caching-redis

Licence
MIT
Version
2.22.7
Deps
2
Size
51 kB
Vulns
0
Weekly
0
Stars
36.5K

Medusa logo

@medusajs/caching-redis

Documentation | Website

Building blocks for digital commerce

Medusa is released under the MIT license. PRs welcome! Discord Chat Follow @medusajs

Redis Caching Module Provider for Medusa: stores the Caching Module's cached data in Redis, with tag-based invalidation and compression of large values. Use it in production so cached data is shared across Medusa instances. It ships with @medusajs/medusa and is registered through the @medusajs/medusa/caching-redis path.

At a glance

Package @medusajs/caching-redis
Type Module Provider (Caching Module)
Provider ID cache-redis
Registered by default No (on Medusa Cloud, registered when CACHE_REDIS_URL is set)
Import from @medusajs/medusa/caching-redis

Installation

No installation needed. The provider is a dependency of @medusajs/medusa. You need a running Redis server.

Usage

The Caching Module is behind the caching feature flag. Enable it with MEDUSA_FF_CACHING=true, then register the provider in the Caching Module's providers array in medusa-config.ts:

import { defineConfig } from "@medusajs/framework/utils"

module.exports = defineConfig({
  // ...
  modules: [
    {
      resolve: "@medusajs/medusa/caching",
      options: {
        providers: [
          {
            resolve: "@medusajs/medusa/caching-redis",
            id: "caching-redis",
            // makes this the default caching provider
            is_default: true,
            options: {
              redisUrl: process.env.CACHE_REDIS_URL,
            },
          },
        ],
      },
    },
  ],
})

Configuration

Option Type Description Default
redisUrl string Required. The Redis connection URL. -
redisOptions RedisOptions Options passed to the ioredis client. Passing them at the top level of options is deprecated. -
ttl number Default time-to-live of cached entries, in seconds. 3600
prefix string Prefix added to all cache keys. "mc:"
compressionThreshold number Minimum size in bytes of a value before it's compressed. 2048
Environment variable Description
MEDUSA_FF_CACHING Set to true to enable the Caching Module.
CACHE_REDIS_URL Value for redisUrl, as used in the example above.

Resources

Keywords