docs: fix events payloads (#14131)
This commit is contained in:
@@ -13183,6 +13183,39 @@ If you execute the workflow, the event is emitted and you can see it in your app
|
||||
|
||||
Any subscribers listening to the event are executed.
|
||||
|
||||
### Emit Event Multiple Times
|
||||
|
||||
You can also emit the event multiple times with `emitEventStep` by passing an array of objects to the `data` property. The event is emitted once per each object in the array.
|
||||
|
||||
For example:
|
||||
|
||||
```ts highlights={highlights}
|
||||
import {
|
||||
createWorkflow,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import {
|
||||
emitEventStep,
|
||||
} from "@medusajs/medusa/core-flows"
|
||||
|
||||
const helloWorldWorkflow = createWorkflow(
|
||||
"hello-world",
|
||||
() => {
|
||||
// ...
|
||||
|
||||
emitEventStep({
|
||||
eventName: "custom.created",
|
||||
data: [
|
||||
{ id: "123" },
|
||||
{ id: "456" },
|
||||
{ id: "789" },
|
||||
]
|
||||
})
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
The event `custom.created` will be emitted three times, once per each object in the array passed to the `data` property. The subscriber listening to the event will be executed three times, each time receiving one of the objects in the array as the event's payload.
|
||||
|
||||
***
|
||||
|
||||
## Emit Event in a Service
|
||||
@@ -42988,6 +43021,77 @@ Avoid caching data that is updated frequently, such as inventory levels or order
|
||||
Caching such data increases the overhead of cache invalidation and may lead to performance degradation.
|
||||
|
||||
|
||||
# How to Clear Cached Data
|
||||
|
||||
In this guide, you'll learn how to clear cached data in Medusa.
|
||||
|
||||
## Why Clear Cache?
|
||||
|
||||
You should mainly cache data that isn't frequently changing, such as product details or categories. However, there are scenarios where you might need to clear the cache.
|
||||
|
||||
For example, if you've integrated a third-party system that updates product information outside of Medusa, or if you've cached data from the third-party system, Medusa won't be aware of these changes.
|
||||
|
||||
In such cases, clearing the cache ensures that Medusa fetches the most up-to-date information from the source rather than relying on outdated cached data.
|
||||
|
||||
***
|
||||
|
||||
## How to Clear Cache
|
||||
|
||||
This section explains how to clear data cached by the Caching Module in Medusa.
|
||||
|
||||
### Identify Cache Tags
|
||||
|
||||
Before clearing the cache, identify the specific cache tags associated with the data you want to clear.
|
||||
|
||||
When you cache entities with the [Query](https://docs.medusajs.com/docs/learn/fundamentals/module-links/query/index.html.md) or [Index Module](https://docs.medusajs.com/docs/learn/fundamentals/module-links/index-module/index.html.md), the Caching Module automatically generates tags based on the entity type and its ID:
|
||||
|
||||
- `Entity:id`: Cache tag for a single record of an entity. For example, `Product:prod_123` caches a single product with the ID `prod_123`.
|
||||
- `Entity:list:*`: Cache tag for a list of records of an entity. For example, `Product:list:*` caches a list of products.
|
||||
|
||||
To clear the cache for a specific product, use the `Product:{id}` tag. To clear the cache for all products, use the `Product:list:*` tag.
|
||||
|
||||
Refer to the [Caching Module Concepts guide](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/infrastructure-modules/caching/concepts#caching-tags-convention/index.html.md) to learn more about cache tags.
|
||||
|
||||
### Clear Cache with Caching Module Service
|
||||
|
||||
To clear cached data, use the [clear](https://docs.medusajs.com/references/caching-service#clear/index.html.md) method of the Caching Module's service. You can resolve the service in a workflow step, API route, subscriber, or scheduled job, then call the `clear` method with the identified cache tags.
|
||||
|
||||
For example, to clear the cache for specific products in a workflow step:
|
||||
|
||||
```ts
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
type ClearProductCacheInput = {
|
||||
productId: string | string[]
|
||||
}
|
||||
|
||||
export const clearProductCacheStep = createStep(
|
||||
"clear-product-cache",
|
||||
async ({ productId }: ClearProductCacheInput, { container }) => {
|
||||
const cachingModuleService = container.resolve(Modules.CACHING)
|
||||
|
||||
const productIds = Array.isArray(productId) ? productId : [productId]
|
||||
|
||||
// Clear cache for all specified products
|
||||
for (const id of productIds) {
|
||||
if (id) {
|
||||
await cachingModuleService.clear({
|
||||
tags: [`Product:${id}`],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return new StepResponse({})
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
In this example, the `clearProductCacheStep` step takes a `productId` (or an array of IDs) as input and clears the cache for each specified product using its cache tag.
|
||||
|
||||
You can then use this step in a workflow to clear the cache whenever necessary, such as after receiving a webhook from a third-party system indicating that product data has changed.
|
||||
|
||||
|
||||
# Create Memcached Caching Module Provider
|
||||
|
||||
In this tutorial, you'll learn how to create a Memcached [Caching Module Provider](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/infrastructure-modules/caching/providers/index.html.md) for your Medusa application.
|
||||
@@ -45323,7 +45427,7 @@ For example:
|
||||
|
||||
### Workflow
|
||||
|
||||
```ts title="src/workflows/charge-customer.ts" highlights={workflowLockHighlights}
|
||||
```ts title="src/workflows/charge-customer.ts"
|
||||
import { createWorkflow } from "@medusajs/framework/workflows-sdk"
|
||||
import { acquireLockStep, releaseLockStep } from "@medusajs/medusa/core-flows"
|
||||
import { chargeCustomerStep } from "./steps/charge-customer-step"
|
||||
@@ -47487,9 +47591,9 @@ Emitted when a customer is created.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the customer
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -47508,9 +47612,9 @@ Emitted when a customer is updated.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the customer
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -47528,9 +47632,9 @@ Emitted when a customer is deleted.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the customer
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -47634,9 +47738,9 @@ to send an email to the invited users, for example.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the invite
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -47654,9 +47758,9 @@ Emitted when invites are deleted.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the invite
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -47676,9 +47780,9 @@ for example.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the invite
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -47855,9 +47959,9 @@ Emitted when orders are completed.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the order
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -47875,9 +47979,9 @@ Emitted when an order is archived.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the order
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48108,9 +48212,9 @@ Emitted when product categories are created.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product category
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48128,9 +48232,9 @@ Emitted when product categories are updated.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product category
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48148,9 +48252,9 @@ Emitted when product categories are deleted.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product category
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48178,9 +48282,9 @@ Emitted when product collections are created.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product collection
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48198,9 +48302,9 @@ Emitted when product collections are updated.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product collection
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48218,9 +48322,9 @@ Emitted when product collections are deleted.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product collection
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48248,9 +48352,9 @@ Emitted when product options are updated.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product option
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48268,9 +48372,9 @@ Emitted when product options are created.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product option
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48288,9 +48392,9 @@ Emitted when product options are deleted.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product option
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48318,9 +48422,9 @@ Emitted when product tags are updated.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product tag
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48338,9 +48442,9 @@ Emitted when product tags are created.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product tag
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48358,9 +48462,9 @@ Emitted when product tags are deleted.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product tag
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48388,9 +48492,9 @@ Emitted when product types are updated.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product type
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48408,9 +48512,9 @@ Emitted when product types are created.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product type
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48428,9 +48532,9 @@ Emitted when product types are deleted.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product type
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48458,9 +48562,9 @@ Emitted when product variants are updated.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product variant
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48479,9 +48583,9 @@ Emitted when product variants are created.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product variant
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48503,9 +48607,9 @@ Emitted when product variants are deleted.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product variant
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48534,9 +48638,9 @@ Emitted when products are updated.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48556,9 +48660,9 @@ Emitted when products are created.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48578,9 +48682,9 @@ Emitted when products are deleted.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the product
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48610,9 +48714,9 @@ Emitted when regions are updated.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the region
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48630,9 +48734,9 @@ Emitted when regions are created.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the region
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48650,9 +48754,9 @@ Emitted when regions are deleted.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the region
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48680,9 +48784,9 @@ Emitted when sales channels are created.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the sales channel
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48700,9 +48804,9 @@ Emitted when sales channels are updated.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the sales channel
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48720,9 +48824,9 @@ Emitted when sales channels are deleted.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the sales channel
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48750,9 +48854,9 @@ Emitted when shipping option types are updated.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the shipping option type
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48770,9 +48874,9 @@ Emitted when shipping option types are created.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the shipping option type
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48790,9 +48894,9 @@ Emitted when shipping option types are deleted.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the shipping option type
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48820,9 +48924,9 @@ Emitted when users are created.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the user
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48842,9 +48946,9 @@ Emitted when users are updated.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the user
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
@@ -48862,9 +48966,9 @@ Emitted when users are deleted.
|
||||
#### Payload
|
||||
|
||||
```ts
|
||||
[{
|
||||
{
|
||||
id, // The ID of the user
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
#### Workflows Emitting this Event
|
||||
|
||||
Reference in New Issue
Block a user