import { Prerequisites, Table } from "docs-ui"
export const metadata = {
title: `Medusa Cache`,
}
# {metadata.title}
In this guide, you'll learn about Medusa Cache.
## What is Medusa Cache?
Medusa Cache is a caching layer that improves your application's performance and reduces costs. It's available to all environments and plans out of the box at no additional cost.
Medusa Cache relies on the existing key/value [Redis](../redis/page.mdx) store already provisioned for environments. Each environment has its own isolated cache.

---
## Enable Medusa Cache
To enable Medusa Cache for your Medusa project deployed on Cloud, set the `caching` feature flag in `medusa-config.ts`:
```ts title="medusa-config.ts"
module.exports = defineConfig({
// ...
featureFlags: {
caching: true,
},
})
```
This will enable all Medusa Cache functionality in your project.
---
## How Does Medusa Cache Work?
### Cached Data in API Routes
By using Medusa Cache, data is cached across several business-critical APIs to boost performance and throughput. This includes all cart-related operations, where the following data is cached:
- Regions
- Promotion codes
- Variant price sets
- Variants
- Shipping options
- Sales channels
- Customers
### Integrated into Query
Medusa Cache is built on the new [Caching Module](!resources!/infrastructure-modules/caching). The module has been integrated into [Query](!docs!/learn/fundamentals/module-links/query) so that `query.graph` calls can be cached easily.
You can enable caching for your custom `query.graph` calls by passing a `cache` option. For example:
```ts
const { data: products } = await query.graph({
entity: "product",
fields: ["id", "title", "handle"],
}, {
cache: {
enable: true,
},
})
```
This code caches the query result. When the same query is made again, the cached result is returned instead of querying the database.

### Automatic Invalidation
By default, data is cached for one hour or until invalidated. Invalidation occurs automatically when related data is created, updated, or deleted.
Learn more about automatic invalidation in the [Caching Module documentation](!resources!/infrastructure-modules/caching/concepts#automatic-cache-invalidation).
---
## Performance Benchmark Comparisons
The following benchmark comparisons demonstrate the performance improvements you can expect with Medusa Cache. These were conducted on a Cloud environment with a standard setup.
Endpoint
Without Medusa Cache (ms)
With Medusa Cache (ms)
Improvement
**Product Operations**
`GET /store/products`
`354.00`
`83.00`
`~77%`
`GET /store/product-categories`
`88.00`
`51.00`
`~42%`
`GET /store/products/:id`
`161.00`
`123.00`
`~24%`
**Cart Operations**
`POST /store/carts/:id/line-items`
`697.00`
`427.00`
`~39%`
`POST /store/carts/:id/shipping-methods`
`1002.00`
`670.00`
`~33%`
`POST /store/carts/:id/promotions`
`302.00`
`203.00`
`~33%`
`GET /store/carts/:id`
`109.00`
`73.00`
`~33%`
`POST /store/carts/:id`
`909.00`
`656.00`
`~28%`
`POST /store/carts`
`446.00`
`329.00`
`~26%`
`POST /store/carts/:id/complete`
`1357.00`
`1018.00`
`~25%`
**Order Operations**
`GET /store/orders/:id`
`119.00`
`81.00`
`~32%`
**Other Operations**
`GET /store/regions`
`89.00`
`51.00`
`~43%`
`GET /store/shipping-options`
`272.00`
`173.00`
`~36%`
`POST /store/payment-collections`
`238.00`
`160.00`
`~33%`
`POST /store/payment-collections/:id/payments`
`152.00`
`102.00`
`~33%`