npm.io
2.22.7 • Published 4d ago

@medusajs/caching

Licence
MIT
Version
2.22.7
Deps
3
Size
98 kB
Vulns
0
Weekly
0
Stars
36.2K

Medusa logo

@medusajs/caching

Documentation | Website

Building blocks for digital commerce

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

Caching Module for Medusa: caches data such as Query and Index Module results in a pluggable caching service like Redis. It replaces the deprecated Cache Modules (@medusajs/cache-inmemory, @medusajs/cache-redis) and uses a provider pattern, so the underlying store is a Caching Module Provider. It ships with @medusajs/medusa and is registered from @medusajs/medusa/caching.

At a glance

Package @medusajs/caching
Type Infrastructure Module
Module key Modules.CACHING ("caching")
Registered by default No
Import from @medusajs/medusa/caching

Features

  • Cache Query and Index Module results, or cache any data directly through the module's service.
  • Pluggable providers, with a default provider selected by is_default (or the only registered provider). Official provider:

Installation

No installation needed. The module ships with @medusajs/medusa. To use it:

  1. Enable the caching feature flag by setting MEDUSA_FF_CACHING=true in your environment.
  2. Register the module with at least one provider in medusa-config.ts. The module throws on startup if no provider is configured.

Usage

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

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

Then resolve the service with container.resolve(Modules.CACHING).

Configuration

Option Type Description Default
providers { resolve: string, id: string, is_default?: boolean, options?: Record<string, unknown> }[] Caching Module Providers to register. -
ttl number Time to keep data in the cache, in seconds. 3600

Resources