Skip to main content

Cache

In this document, you’ll learn about Cache Modules in Medusa, how they work, and which modules Medusa provides.

Overview

Cache is used in Medusa to store the results of computations such as price selection or various tax calculations. The caching layer in Medusa is implemented as a module. This allows you to replace the underlying database/cache store in your project.

Modules are packages that export a service. The main service exported from a cache module has to implement the ICacheService interface exported from the @medusajs/types package.

During the app startup, the modules loader will load the service into the dependency injection container to be available as cacheService to the rest of the commerce application.


Available Modules

Medusa default starter project comes with the in-memory cache module (@medusajs/cache-inmemory). In-memory cache uses a plain JS Map object to store data, which is great for testing and development purposes.

For production environments, there is the Redis cache module package (@medusajs/cache-redis) that you can install.


Custom Development

Developers can create custom cache modules to implement their custom cache logic. The module can be installed and used in any Medusa backend.

Was this page helpful?