1 import { CardList } from "docs-ui"
2
3 export const metadata = {
4 title: `Cache Module`,
5 }
6
7 # {metadata.title}
8
9 In this document, you'll learn what a Cache Module is and how to use it in your Medusa application.
10
11 <Note title="Deprecation Notice">
12
13 The Cache Module is deprecated starting from [Medusa v2.11.0](https://github.com/medusajs/medusa/releases/tag/v2.11.0). Use the [Caching Module](../caching/page.mdx) instead.
14
15 </Note>
16
17 ## What is a Cache Module?
18
19 A Cache Module is used to cache the results of computations such as price selection or various tax calculations.
20
21 The underlying database, third-party service, or caching logic is flexible since it's implemented in a module. You can choose from Medusa’s cache modules or create your own to support something more suitable for your architecture.
22
23 ### Default Cache Module
24
25 By default, Medusa uses the [In-Memory Cache Module](./in-memory/page.mdx). This module uses a plain JavaScript Map object to store the cache data. While this is suitable for development, it's recommended to use other Cache Modules, such as the [Redis Cache Module](./redis/page.mdx), for production. You can also [Create a Cache Module](./create/page.mdx).
26
27 ---
28
29 ## How to Use the Cache Module?
30
31 You can use the registered Cache Module as part of the [workflows](!docs!/learn/fundamentals/workflows) you build for your custom features. A workflow is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism.
32
33 In a step of your workflow, you can resolve the Cache Module's service and use its methods to cache data, retrieve cached data, or clear the cache.
34
35 For example:
36
37 ```ts
38 import { Modules } from "@medusajs/framework/utils"
39 import {
40 createStep,
41 createWorkflow,
42 } from "@medusajs/framework/workflows-sdk"
43
44 const step1 = createStep(
45 "step-1",
46 async ({}, { container }) => {
47 const cacheModuleService = container.resolve(
48 Modules.CACHE
49 )
50
51 await cacheModuleService.set("key", "value")
52 }
53 )
54
55 export const workflow = createWorkflow(
56 "workflow-1",
57 () => {
58 step1()
59 }
60 )
61 ```
62
63 In the example above, you create a workflow that has a step. In the step, you resolve the service of the Cache Module from the [Medusa container](!docs!/learn/fundamentals/medusa-container).
64
65 Then, you use the `set` method of the Cache Module to cache the value `"value"` with the key `"key"`.
66
67 ---
68
69 ## List of Cache Modules
70
71 Medusa provides the following Cache Modules. You can use one of them, or [Create a Cache Module](./create/page.mdx).
72
73 <CardList
74 items={[
75 {
76 title: "In-Memory",
77 href: "/infrastructure-modules/cache/in-memory",
78 badge: {
79 variant: "neutral",
80 children: "For Development"
81 }
82 },
83 {
84 title: "Redis",
85 href: "/infrastructure-modules/cache/redis",
86 badge: {
87 variant: "green",
88 children: "For Production"
89 }
90 }
91 ]}
92 />