Generated the following references: - `api_key_models` - `auth_models` - `cart_models` - `core_flows` - `currency_models` - `customer_models` - `file` - `file_service` - `fulfillment` - `fulfillment_models` - `helper_steps` - `inventory_next_models` - `js_sdk` - `module_events` - `modules` - `notification` - `notification_service` - `order` - `order_models` - `payment` - `payment_models` - `pricing_models` - `product_models` - `promotion` - `promotion_models` - `region_models` - `sales_channel_models` - `stock_location_next_models` - `store_models` - `tax_models` - `types` - `user_models` - `utils` - `workflows` --- > [!NOTE] > Regenerates documentation references with updated schemas/fields and source links, adds locking guidance to fulfillment delivery workflow, expands notification step IO, and tweaks examples/sample values. > > - **Docs Generation**: > - Regenerated reference pages across `core_flows`, `fulfillment`, `inventory`, `order`, etc., with updated TypeList schemas and examples. > - **Fulfillment Workflows/Steps**: > - Updated IO schemas (e.g., added `custom_display_id` on `OrderDTO`, `carry_over_promotions` on `OrderChangeDTO`). > - Added locking guidance and workflow steps (`acquireLockStep`/`releaseLockStep`) to `markFulfillmentAsDeliveredWorkflow` plus new note/tag. > - Refreshed example snippets and sample values. > - **Notification Step** (`sendNotificationsStep`): > - Input expanded with `from`, `content`, `provider_data`, `attachments`; `template` now optional. > - Output includes `provider_data` and `attachments` fields. > - **Order Steps/Workflows**: > - IO schemas updated to include `custom_display_id` and `carry_over_promotions` where applicable; added `ordering` on change actions. > - Example payloads adjusted (IDs, currencies, amounts). > - **Meta**: > - Updated `<SourceCodeLink>` URLs to new commit hashes throughout. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit eeb0dac7b19d51860531a491208b2b3b853aa4db. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
116 lines
4.6 KiB
Plaintext
116 lines
4.6 KiB
Plaintext
---
|
||
slug: /references/cache-service
|
||
tags:
|
||
- cache
|
||
- server
|
||
- how to
|
||
sidebar_label: Use Cache Module
|
||
keywords:
|
||
- cache
|
||
- provider
|
||
- integration
|
||
---
|
||
|
||
import { TypeList } from "docs-ui"
|
||
|
||
# How to Use Cache Module
|
||
|
||
In this document, you’ll learn about the different methods in the Cache Module's service and how to use them.
|
||
|
||
:::note[Deprecation Notice]
|
||
|
||
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](https://docs.medusajs.com/resources/infrastructure-modules/caching) instead.
|
||
|
||
:::
|
||
|
||
|
||
---
|
||
|
||
## Resolve Cache Module's Service
|
||
|
||
In your workflow's step, you can resolve the Cache Module's service from the Medusa container:
|
||
|
||
```ts
|
||
import { Modules } from "@medusajs/framework/utils"
|
||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||
|
||
const step1 = createStep(
|
||
"step-1",
|
||
async ({}, { container }) => {
|
||
const cacheModuleService = container.resolve(
|
||
Modules.CACHE
|
||
)
|
||
|
||
// TODO use cacheModuleService
|
||
}
|
||
)
|
||
```
|
||
|
||
This will resolve the service of the configured Cache Module, which is the [In-Memory Cache Module](https://docs.medusajs.com/resources/infrastructure-modules/cache/in-memory) by default.
|
||
|
||
You can then use the Cache Module's service's methods in the step. The rest of this guide details these methods.
|
||
|
||
---
|
||
|
||
## get
|
||
|
||
This method retrieves data from the cache.
|
||
|
||
### Example
|
||
|
||
```ts
|
||
const data = await cacheModuleService.get("my-key")
|
||
```
|
||
|
||
### Type Parameters
|
||
|
||
<TypeList types={[{"name":"T","type":"`object`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="get"/>
|
||
|
||
### Parameters
|
||
|
||
<TypeList types={[{"name":"key","type":"`string`","description":"The key of the item to retrieve.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="get"/>
|
||
|
||
### Returns
|
||
|
||
<TypeList types={[{"name":"Promise","type":"Promise<null \\| T>","optional":false,"defaultValue":"","description":"The item that was stored in the cache. If the item was not found, null is returned.","expandable":false,"children":[{"name":"null \\| T","type":"`null` \\| T","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="get"/>
|
||
|
||
___
|
||
|
||
## invalidate
|
||
|
||
This method removes an item from the cache.
|
||
|
||
### Example
|
||
|
||
```ts
|
||
await cacheModuleService.invalidate("my-key")
|
||
```
|
||
|
||
### Parameters
|
||
|
||
<TypeList types={[{"name":"key","type":"`string`","description":"The key of the item to remove.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="invalidate"/>
|
||
|
||
### Returns
|
||
|
||
<TypeList types={[{"name":"Promise","type":"Promise<void>","optional":false,"defaultValue":"","description":"This method removes an item from the cache.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="invalidate"/>
|
||
|
||
___
|
||
|
||
## set
|
||
|
||
This method stores data in the cache.
|
||
|
||
### Example
|
||
|
||
```ts
|
||
await cacheModuleService.set("my-key", { product_id: "prod_123" }, 60)
|
||
```
|
||
|
||
### Parameters
|
||
|
||
<TypeList types={[{"name":"key","type":"`string`","description":"The key of the item to store.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"data","type":"`unknown`","description":"The data to store in the cache.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"ttl","type":"`number`","description":"The time-to-live (TTL) value in seconds. If not provided, the default TTL value is used. The default value is based on the used Cache Module.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="set"/>
|
||
|
||
### Returns
|
||
|
||
<TypeList types={[{"name":"Promise","type":"Promise<void>","optional":false,"defaultValue":"","description":"This method stores data in the cache.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="set"/>
|