Files
2025-12-17 18:20:19 +02:00

51 lines
7.0 KiB
Plaintext

import { TypeList } from "docs-ui"
# CachingUtils
## Functions
- [Cached](page.mdx#cached)
- [useCache](page.mdx#usecache)
## Functions
### Cached
This function is used to cache the result of a method call.
#### Type Parameters
<TypeList types={[{"name":"Target","type":"`object`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"PropertyKey","type":"`string` \\| `number` \\| `symbol`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="Cached"/>
#### Parameters
<TypeList types={[{"name":"options","type":"`object`","description":"The options for the cache.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"container","type":"[MedusaContainer](../../medusa/types/medusa.MedusaContainer/page.mdx) \\| (`this`: Target) => [MedusaContainer](../../medusa/types/medusa.MedusaContainer/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"key","type":"`string` \\| (`args`: [TargetMethodArgs](../types/utils.TargetMethodArgs/page.mdx)&#60;Target, PropertyKey&#62;, `cachingModule`: [ICachingModuleService](../../types/CachingTypes/interfaces/types.CachingTypes.ICachingModuleService/page.mdx)) => `string` \\| `any`[] \\| Promise&#60;any[]&#62; \\| Promise&#60;string&#62;","description":"The key to use for the cache.\nIf a function is provided, it will be called with the arguments as the first argument and the\ncontainer as the second argument.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enable","type":"`boolean` \\| (`args`: [TargetMethodArgs](../types/utils.TargetMethodArgs/page.mdx)&#60;Target, PropertyKey&#62;) => `undefined` \\| `boolean`","description":"Whether to enable the cache. This is only useful if you want to enable without providing any\nother options.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"`string`[] \\| (`args`: [TargetMethodArgs](../types/utils.TargetMethodArgs/page.mdx)&#60;Target, PropertyKey&#62;) => `undefined` \\| `string`[]","description":"The tags to use for the cache.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"ttl","type":"`number` \\| (`args`: [TargetMethodArgs](../types/utils.TargetMethodArgs/page.mdx)&#60;Target, PropertyKey&#62;) => `undefined` \\| `number`","description":"The time-to-live (TTL) value in seconds.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"autoInvalidate","type":"`boolean` \\| (`args`: [TargetMethodArgs](../types/utils.TargetMethodArgs/page.mdx)&#60;Target, PropertyKey&#62;) => `undefined` \\| `boolean`","description":"Whether to auto invalidate the cache whenever it is possible.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"providers","type":"`string`[] \\| (`args`: [TargetMethodArgs](../types/utils.TargetMethodArgs/page.mdx)&#60;Target, PropertyKey&#62;) => `undefined` \\| `string`[]","description":"The providers to use for the cache.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="Cached"/>
#### Returns
<TypeList types={[{"name":"(target: Target, propertyKey: PropertyKey, descriptor: PropertyDescriptor) => PropertyDescriptor","type":"(`target`: Target, `propertyKey`: PropertyKey, `descriptor`: `PropertyDescriptor`) => `PropertyDescriptor`","optional":false,"defaultValue":"","description":"The original method with the cache applied.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="Cached"/>
##### Parameters
<TypeList types={[{"name":"target","type":"Target","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"propertyKey","type":"PropertyKey","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"descriptor","type":"`PropertyDescriptor`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="__type"/>
##### Returns
<TypeList types={[{"name":"PropertyDescriptor","type":"`PropertyDescriptor`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="__type"/>
### useCache
This function is used to cache the result of a function call.
#### 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="useCache"/>
#### Parameters
<TypeList types={[{"name":"cb","type":"(...`args`: `any`[]) => Promise&#60;T&#62;","description":"The callback to execute.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"`object`","description":"The options for the cache.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"key","type":"`string` \\| `any`[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"container","type":"[MedusaContainer](../../medusa/types/medusa.MedusaContainer/page.mdx)","description":"The Medusa Container extends [Awilix](https://github.com/jeffijoe/awilix) to\nprovide dependency injection functionalities.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"enable","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"tags","type":"`string`[]","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"ttl","type":"`number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"autoInvalidate","type":"`boolean`","description":"Whethere the default strategy should auto invalidate the cache whenever it is possible.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"providers","type":"`string`[]","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="useCache"/>
#### Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;T&#62;","optional":false,"defaultValue":"","description":"The result of the callback.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="useCache"/>