@medusajs/cache-inmemory 2.22.0-snapshot-20261020204851 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/AGENTS.md +43 -0
  2. package/README.md +71 -14
  3. package/package.json +7 -3
package/AGENTS.md ADDED
@@ -0,0 +1,43 @@
1
+ # @medusajs/cache-inmemory
2
+
3
+ In-memory implementation of the legacy Cache Module (`Modules.CACHE`, container key `"cache"`). It is the default Cache Module registered by `defineConfig` for non-Cloud projects. Deprecated since v2.11.0 in favor of the Caching Module (`@medusajs/caching`).
4
+
5
+ ## Using this package
6
+
7
+ - Registered by default as `@medusajs/medusa/cache-inmemory` (`MODULE_PACKAGE_NAMES[Modules.CACHE]`). Explicit config:
8
+
9
+ ```ts
10
+ module.exports = defineConfig({
11
+ modules: [
12
+ {
13
+ resolve: "@medusajs/medusa/cache-inmemory",
14
+ options: { ttl: 30 },
15
+ },
16
+ ],
17
+ })
18
+ ```
19
+
20
+ - Options (`InMemoryCacheModuleOptions`): `ttl` in seconds, default `30`.
21
+ - Resolve: `container.resolve(Modules.CACHE)` (`ICacheService`). Still used internally by the Auth Module (MFA challenges, OAuth state).
22
+ - Methods: `get(key)`, `set(key, data, ttl?)`, `invalidate(key)` (supports `*`), `clear()` (in-memory only, not on `ICacheService`).
23
+ - No data models, events, links, or providers.
24
+ - Docs: https://docs.medusajs.com/resources/infrastructure-modules/cache/in-memory.md, https://docs.medusajs.com/resources/infrastructure-modules/caching.md
25
+
26
+ ## Architecture
27
+
28
+ - `src/services/inmemory-cache.ts`: a `Map` store plus a `setTimeout` per key (`unref()`'d) that evicts the key at expiry; `get` also checks `expire`.
29
+ - `src/initialize/index.ts`: `initialize(options)` bootstraps the module standalone via `MedusaModule.bootstrap`.
30
+ - The module definition is a plain `ModuleExports` object (`{ service }`), not `Module(...)`, and has no joiner config.
31
+
32
+ ## Development
33
+
34
+ ```bash
35
+ yarn build
36
+ yarn test # src/services/__tests__/inmemory-cache.js
37
+ ```
38
+
39
+ ## Gotchas
40
+
41
+ - State is per process: not shared across server/worker instances and lost on restart. Use Redis-backed caching in multi-instance deployments.
42
+ - `set(key, data, 0)` is a no-op (nothing is cached).
43
+ - `invalidate` builds a regex with `key.replace("*", ".*")`: only the first `*` is expanded and the pattern is unanchored, so `"ps:*"` also matches keys that merely contain `ps:`.
package/README.md CHANGED
@@ -1,25 +1,82 @@
1
- # Medusa Cache In-memory
1
+ <p align="center">
2
+ <a href="https://www.medusajs.com">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/59018053/229103275-b5e482bb-4601-46e6-8142-244f531cebdb.svg">
5
+ <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
6
+ <img alt="Medusa logo" src="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
7
+ </picture>
8
+ </a>
9
+ </p>
10
+ <h1 align="center">
11
+ @medusajs/cache-inmemory
12
+ </h1>
2
13
 
3
- Medusa in-memory cache module. Use plain JS Map as a cache store.
14
+ <h4 align="center">
15
+ <a href="https://docs.medusajs.com">Documentation</a> |
16
+ <a href="https://www.medusajs.com">Website</a>
17
+ </h4>
18
+
19
+ <p align="center">
20
+ Building blocks for digital commerce
21
+ </p>
22
+ <p align="center">
23
+ <a href="https://github.com/medusajs/medusa/blob/develop/LICENSE">
24
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="Medusa is released under the MIT license." />
25
+ </a>
26
+ <a href="https://github.com/medusajs/medusa/blob/develop/CONTRIBUTING.md">
27
+ <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs welcome!" />
28
+ </a>
29
+ <a href="https://discord.gg/xpCwq3Kfn8">
30
+ <img src="https://img.shields.io/badge/chat-on%20discord-7289DA.svg" alt="Discord Chat" />
31
+ </a>
32
+ <a href="https://twitter.com/intent/follow?screen_name=medusajs">
33
+ <img src="https://img.shields.io/twitter/follow/medusajs.svg?label=Follow%20@medusajs" alt="Follow @medusajs" />
34
+ </a>
35
+ </p>
36
+
37
+ In-Memory Cache Module for Medusa: stores cached data in the Node.js process memory, for development and testing. **Deprecated since Medusa v2.11.0**: use the [Caching Module](../caching) (`@medusajs/caching`) instead. It ships with `@medusajs/medusa` and is the default Cache Module when no Redis Cache Module is configured.
38
+
39
+ ## At a glance
40
+
41
+ | | |
42
+ | --- | --- |
43
+ | Package | `@medusajs/cache-inmemory` |
44
+ | Type | Infrastructure Module (deprecated) |
45
+ | Module key | `Modules.CACHE` (`"cache"`) |
46
+ | Registered by default | Yes |
47
+ | Import from | `@medusajs/medusa/cache-inmemory` |
4
48
 
5
49
  ## Installation
6
50
 
7
- ```
8
- yarn add @medusajs/cache-inmemory
9
- ```
51
+ No installation needed. The module ships with `@medusajs/medusa` and is registered by default.
10
52
 
11
- ## Options
53
+ ## Usage
12
54
 
13
- ```
14
- {
15
- ttl?: number // Time to keep data in cache (in seconds)
16
- }
55
+ To change its options, register it in `medusa-config.ts`:
56
+
57
+ ```ts title="medusa-config.ts"
58
+ import { defineConfig } from "@medusajs/framework/utils"
59
+
60
+ module.exports = defineConfig({
61
+ // ...
62
+ modules: [
63
+ {
64
+ resolve: "@medusajs/medusa/cache-inmemory",
65
+ options: {
66
+ ttl: 30,
67
+ },
68
+ },
69
+ ],
70
+ })
17
71
  ```
18
72
 
19
- ### Note
73
+ ## Configuration
20
74
 
21
- Recommended for testing and development. For production, use Redis cache module.
75
+ | Option | Type | Description | Default |
76
+ | --- | --- | --- | --- |
77
+ | `ttl` | `number` | Time to keep data in the cache, in seconds. | `30` |
22
78
 
23
- ### Other caching modules
79
+ ## Resources
24
80
 
25
- - [Medusa Cache Redis](../cache-redis/README.md)
81
+ - [In-Memory Cache Module](https://docs.medusajs.com/resources/infrastructure-modules/cache/in-memory)
82
+ - [Migrate from the Cache Module to the Caching Module](https://docs.medusajs.com/resources/infrastructure-modules/caching/migrate-cache)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/cache-inmemory",
3
- "version": "2.22.0-snapshot-20261020204851",
3
+ "version": "2.22.0",
4
4
  "description": "In-memory Cache Module for Medusa",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -19,14 +19,18 @@
19
19
  },
20
20
  "files": [
21
21
  "dist",
22
+ "AGENTS.md",
22
23
  "!dist/**/__tests__",
23
24
  "!dist/**/__mocks__",
24
25
  "!dist/**/__fixtures__"
25
26
  ],
27
+ "llms": "https://docs.medusajs.com/llms.txt",
28
+ "llmsFull": "https://docs.medusajs.com/llms-full.txt",
29
+ "mcpServer": "https://docs.medusajs.com/mcp",
26
30
  "author": "Medusa",
27
31
  "license": "MIT",
28
32
  "devDependencies": {
29
- "@medusajs/framework": "2.22.0-snapshot-20261020204851"
33
+ "@medusajs/framework": "2.22.0"
30
34
  },
31
35
  "scripts": {
32
36
  "watch": "yarn run -T tsc --build --watch",
@@ -34,6 +38,6 @@
34
38
  "test": "../../../node_modules/.bin/jest --passWithNoTests"
35
39
  },
36
40
  "peerDependencies": {
37
- "@medusajs/framework": "2.22.0-snapshot-20261020204851"
41
+ "@medusajs/framework": "2.22.0"
38
42
  }
39
43
  }