express-memorize 1.0.0 → 1.3.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 (68) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/LICENSE +21 -0
  3. package/README.md +230 -0
  4. package/dist/MemorizeStore.d.ts +83 -31
  5. package/dist/MemorizeStore.d.ts.map +1 -1
  6. package/dist/MemorizeStore.js +87 -10
  7. package/dist/MemorizeStore.js.map +1 -1
  8. package/dist/domain/CacheEntry.d.ts +14 -0
  9. package/dist/domain/CacheEntry.d.ts.map +1 -0
  10. package/dist/domain/CacheEntry.js +3 -0
  11. package/dist/domain/CacheEntry.js.map +1 -0
  12. package/dist/domain/CacheInfo.d.ts +12 -0
  13. package/dist/domain/CacheInfo.d.ts.map +1 -0
  14. package/dist/domain/CacheInfo.js +3 -0
  15. package/dist/domain/CacheInfo.js.map +1 -0
  16. package/dist/domain/Memorize.d.ts +148 -0
  17. package/dist/domain/Memorize.d.ts.map +1 -0
  18. package/dist/domain/Memorize.js +3 -0
  19. package/dist/domain/Memorize.js.map +1 -0
  20. package/dist/domain/MemorizeCallOptions.d.ts +24 -0
  21. package/dist/domain/MemorizeCallOptions.d.ts.map +1 -0
  22. package/dist/domain/MemorizeCallOptions.js +3 -0
  23. package/dist/domain/MemorizeCallOptions.js.map +1 -0
  24. package/dist/domain/MemorizeDeleteEvent.d.ts +18 -0
  25. package/dist/domain/MemorizeDeleteEvent.d.ts.map +1 -0
  26. package/dist/domain/MemorizeDeleteEvent.js +3 -0
  27. package/dist/domain/MemorizeDeleteEvent.js.map +1 -0
  28. package/dist/domain/MemorizeEmptyEvent.d.ts +16 -0
  29. package/dist/domain/MemorizeEmptyEvent.d.ts.map +1 -0
  30. package/dist/domain/MemorizeEmptyEvent.js +3 -0
  31. package/dist/domain/MemorizeEmptyEvent.js.map +1 -0
  32. package/dist/domain/MemorizeEvent.d.ts +7 -0
  33. package/dist/domain/MemorizeEvent.d.ts.map +1 -0
  34. package/dist/domain/MemorizeEvent.js +3 -0
  35. package/dist/domain/MemorizeEvent.js.map +1 -0
  36. package/dist/domain/MemorizeEventType.d.ts +22 -0
  37. package/dist/domain/MemorizeEventType.d.ts.map +1 -0
  38. package/dist/domain/MemorizeEventType.js +26 -0
  39. package/dist/domain/MemorizeEventType.js.map +1 -0
  40. package/dist/domain/MemorizeExpireEvent.d.ts +17 -0
  41. package/dist/domain/MemorizeExpireEvent.d.ts.map +1 -0
  42. package/dist/domain/MemorizeExpireEvent.js +3 -0
  43. package/dist/domain/MemorizeExpireEvent.js.map +1 -0
  44. package/dist/domain/MemorizeOptions.d.ts +16 -0
  45. package/dist/domain/MemorizeOptions.d.ts.map +1 -0
  46. package/dist/domain/MemorizeOptions.js +3 -0
  47. package/dist/domain/MemorizeOptions.js.map +1 -0
  48. package/dist/domain/MemorizeSetEvent.d.ts +25 -0
  49. package/dist/domain/MemorizeSetEvent.d.ts.map +1 -0
  50. package/dist/domain/MemorizeSetEvent.js +3 -0
  51. package/dist/domain/MemorizeSetEvent.js.map +1 -0
  52. package/dist/domain/index.d.ts +12 -0
  53. package/dist/domain/index.d.ts.map +1 -0
  54. package/dist/domain/index.js +6 -0
  55. package/dist/domain/index.js.map +1 -0
  56. package/dist/index.d.ts +3 -2
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +3 -1
  59. package/dist/index.js.map +1 -1
  60. package/dist/memorize.d.ts +51 -18
  61. package/dist/memorize.d.ts.map +1 -1
  62. package/dist/memorize.js +52 -0
  63. package/dist/memorize.js.map +1 -1
  64. package/dist/utils/globToRegex.d.ts +12 -0
  65. package/dist/utils/globToRegex.d.ts.map +1 -0
  66. package/dist/utils/globToRegex.js +41 -0
  67. package/dist/utils/globToRegex.js.map +1 -0
  68. package/package.json +30 -6
package/CHANGELOG.md ADDED
@@ -0,0 +1,53 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ This file is automatically updated by [release-please](https://github.com/googleapis/release-please) based on [Conventional Commits](https://www.conventionalcommits.org/).
6
+
7
+ ## [1.3.0](https://github.com/ElJijuna/express-memorize/compare/v1.2.0...v1.3.0) (2026-03-26)
8
+
9
+
10
+ ### Features
11
+
12
+ * add 'deleteMatching' to delete with pattern from cache. ([3564f0a](https://github.com/ElJijuna/express-memorize/commit/3564f0a316c54031216fce8df042b78c81d27fe3))
13
+ * add config in middleware to disable cache to specific paths. ([cf89777](https://github.com/ElJijuna/express-memorize/commit/cf897777a2c5c984466ec6061a1befbddf73f502))
14
+
15
+ ## [1.2.0](https://github.com/ElJijuna/express-memorize/compare/v1.1.0...v1.2.0) (2026-03-24)
16
+
17
+
18
+ ### Features
19
+
20
+ * refactor to separate in domain files (one file per scope) and update memorize and Memorize store with implementation ([4f41f8c](https://github.com/ElJijuna/express-memorize/commit/4f41f8c0c350df36dcf111315857b6fd34c1a031))
21
+
22
+ ## [1.1.0](https://github.com/ElJijuna/express-memorize/compare/v1.0.0...v1.1.0) (2026-03-24)
23
+
24
+
25
+ ### Features
26
+
27
+ * add evento to notify when cache is empty. ([8484f29](https://github.com/ElJijuna/express-memorize/commit/8484f29f1d1f2bd275970a0c02fa9b64a46576b9))
28
+
29
+ ## 1.0.0 (2026-03-24)
30
+
31
+
32
+ ### Features
33
+
34
+ * add events to log activity in memory store. ([5b3905b](https://github.com/ElJijuna/express-memorize/commit/5b3905b898a5d91c4c61510dd5d8c92eabf096e9))
35
+ * add github action to publish in NPM ([7f79eca](https://github.com/ElJijuna/express-memorize/commit/7f79eca766356280f677411b166c8e2608140d16))
36
+ * add middleware to use memorize. ([73a02a0](https://github.com/ElJijuna/express-memorize/commit/73a02a096750ec66bb8d9c183b0f07c2aeb3cd83))
37
+ * add tests and express client to execute local implementation. ([75d3cf8](https://github.com/ElJijuna/express-memorize/commit/75d3cf81f979a04ef9f0964a444e2966a2ba8164))
38
+ * add validation to only add to store GET methods in middleware. ([04e2918](https://github.com/ElJijuna/express-memorize/commit/04e291884ab083321838cca40755e2c02e98ec6c))
39
+
40
+ ## [1.0.0] - 2026-03-24
41
+
42
+ ### Features
43
+
44
+ - In-memory cache middleware for Express.js
45
+ - Key-value store using full request path (`originalUrl`) as key
46
+ - TTL support with automatic expiry via `setTimeout`
47
+ - Per-route TTL override
48
+ - Caches only `GET` requests with `2xx` status codes
49
+ - `Content-Type` preservation on cache hits
50
+ - `X-Cache: HIT | MISS` response header
51
+ - Cache management API: `get`, `getAll`, `delete`, `clear`
52
+ - Event system: `set`, `delete`, `expire` hooks
53
+ - Full TypeScript support with declaration files
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ElJijuna
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,230 @@
1
+ # express-memorize
2
+
3
+ <p align="center">
4
+ <a href="https://www.npmjs.com/package/express-memorize"><img src="https://img.shields.io/npm/v/express-memorize?color=blue&label=npm" alt="npm version" /></a>
5
+ <a href="https://www.npmjs.com/package/express-memorize"><img src="https://img.shields.io/npm/dm/express-memorize?color=blue" alt="npm downloads" /></a>
6
+ <a href="https://github.com/ElJijuna/express-memorize/actions"><img src="https://github.com/ElJijuna/express-memorize/actions/workflows/publish.yml/badge.svg" alt="CI" /></a>
7
+ <a href="https://github.com/ElJijuna/express-memorize/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="license" /></a>
8
+ <img src="https://img.shields.io/badge/TypeScript-5-blue?logo=typescript&logoColor=white" alt="TypeScript" />
9
+ </p>
10
+
11
+ <p align="center">
12
+ In-memory cache middleware for <strong>Express.js</strong>.<br/>
13
+ Caches <code>GET</code> responses with optional TTL — zero dependencies, fully typed.
14
+ </p>
15
+
16
+ ---
17
+
18
+ ## Features
19
+
20
+ - Caches `GET` responses automatically when status code is `2xx`
21
+ - Per-route TTL override
22
+ - Event hooks: `set`, `delete`, `expire`
23
+ - Cache inspection and invalidation API
24
+ - `X-Cache: HIT | MISS` response header
25
+ - Zero runtime dependencies
26
+ - Full TypeScript support
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ npm install express-memorize
32
+ ```
33
+
34
+ ## Quick Start
35
+
36
+ ```typescript
37
+ import express from 'express';
38
+ import { memorize } from 'express-memorize';
39
+
40
+ const app = express();
41
+ const cache = memorize({ ttl: 30_000 }); // 30 seconds global TTL
42
+
43
+ app.get('/users', cache(), async (req, res) => {
44
+ const users = await db.getUsers();
45
+ res.json({ data: users });
46
+ });
47
+
48
+ app.listen(3000);
49
+ ```
50
+
51
+ The first request computes the response normally. Every subsequent `GET /users` is served from memory until the TTL expires.
52
+
53
+ ## Usage
54
+
55
+ ### Global middleware
56
+
57
+ Apply the cache to the entire application with `app.use()`. Every `GET` route is cached automatically — non-`GET` requests are bypassed without any extra configuration.
58
+
59
+ ```typescript
60
+ const cache = memorize({ ttl: 60_000 });
61
+
62
+ app.use(cache()); // applies to all GET routes
63
+
64
+ app.get('/users', (req, res) => { res.json({ data: users }) });
65
+ app.get('/products', (req, res) => { res.json({ data: products }) });
66
+ // POST, PUT, PATCH, DELETE routes are unaffected
67
+ ```
68
+
69
+ ### Per-route cache
70
+
71
+ ```typescript
72
+ const cache = memorize({ ttl: 60_000 });
73
+
74
+ app.get('/products', cache(), (req, res) => {
75
+ res.json({ data: products });
76
+ });
77
+ ```
78
+
79
+ ### Per-route TTL override
80
+
81
+ ```typescript
82
+ const cache = memorize({ ttl: 60_000 }); // global: 60s
83
+
84
+ app.get('/users', cache(), handler); // 60s
85
+ app.get('/products', cache({ ttl: 10_000 }), handler); // override: 10s
86
+ app.get('/config', cache({ ttl: 0 }), handler); // no expiry
87
+ ```
88
+
89
+ ### Cache invalidation
90
+
91
+ ```typescript
92
+ const cache = memorize({ ttl: 30_000 });
93
+
94
+ app.get('/users', cache(), (req, res) => {
95
+ res.json({ data: users });
96
+ });
97
+
98
+ app.post('/users', (req, res) => {
99
+ users.push(req.body);
100
+ cache.delete('/users'); // invalidate after mutation
101
+ res.status(201).json({ data: req.body });
102
+ });
103
+ ```
104
+
105
+ ### Pattern-based invalidation
106
+
107
+ Use `cache.deleteMatching(pattern)` to remove all cache entries whose keys match a glob pattern. This is useful when you don't know the exact key — for example, when a URL may have different query strings.
108
+
109
+ ```typescript
110
+ // Cached keys: /api/users/abc123, /api/users/abc123?lang=es, /api/users/abc123?page=1
111
+ app.put('/users/:id', (req, res) => {
112
+ users.update(req.params.id, req.body);
113
+
114
+ // Remove all cached variants of this user, regardless of query params
115
+ const deleted = cache.deleteMatching(`**/users/${req.params.id}*`);
116
+ console.log(`${deleted} cache entries removed`);
117
+
118
+ res.json({ ok: true });
119
+ });
120
+ ```
121
+
122
+ **Glob rules:**
123
+
124
+ | Pattern | Behaviour |
125
+ |---------|-----------|
126
+ | `*` | Matches any sequence of characters **within** a single path segment (does not cross `/`) |
127
+ | `**` | Matches any sequence of characters **across** path segments (crosses `/`) |
128
+ | `?` | Matches any single character except `/` |
129
+
130
+ `deleteMatching` returns the number of entries removed and emits a `delete` event for each one.
131
+
132
+ ### Event hooks
133
+
134
+ ```typescript
135
+ const cache = memorize({ ttl: 30_000 });
136
+
137
+ cache.on('set', (e) => {
138
+ console.log(`[cache] stored ${e.key} — expires in ${e.expiresAt ? e.expiresAt - Date.now() : '∞'}ms`);
139
+ });
140
+
141
+ cache.on('delete', (e) => {
142
+ console.log(`[cache] deleted ${e.key}`);
143
+ });
144
+
145
+ cache.on('expire', (e) => {
146
+ console.log(`[cache] expired ${e.key}`);
147
+ });
148
+ ```
149
+
150
+ ### Inspect the cache
151
+
152
+ ```typescript
153
+ cache.get('/users'); // CacheInfo | null — single entry
154
+ cache.getAll(); // Record<string, CacheInfo> — all active entries
155
+ ```
156
+
157
+ `CacheInfo` shape:
158
+
159
+ ```typescript
160
+ {
161
+ key: string;
162
+ body: unknown;
163
+ statusCode: number;
164
+ contentType: string;
165
+ expiresAt: number | null;
166
+ remainingTtl: number | null; // ms until expiry, null if no TTL
167
+ }
168
+ ```
169
+
170
+ ### Clear the cache
171
+
172
+ ```typescript
173
+ cache.delete('/users'); // remove one entry
174
+ cache.deleteMatching('**/users/*'); // remove all /users/* entries
175
+ cache.clear(); // remove all entries
176
+ ```
177
+
178
+ ## API Reference
179
+
180
+ ### `memorize(options?)`
181
+
182
+ Creates a cache instance. Returns a `Memorize` object.
183
+
184
+ | Option | Type | Default | Description |
185
+ |--------|------|---------|-------------|
186
+ | `ttl` | `number` | `undefined` | Time-to-live in milliseconds. Omit for no expiry. |
187
+
188
+ ### `cache(options?)`
189
+
190
+ Returns an Express `RequestHandler` middleware. Can override the global TTL.
191
+
192
+ | Option | Type | Default | Description |
193
+ |--------|------|---------|-------------|
194
+ | `ttl` | `number` | global `ttl` | TTL override for this specific route. |
195
+
196
+ ### Cache management
197
+
198
+ | Method | Signature | Description |
199
+ |--------|-----------|-------------|
200
+ | `get` | `(key: string) => CacheInfo \| null` | Returns info for a cached key. |
201
+ | `getAll` | `() => Record<string, CacheInfo>` | Returns all active cache entries. |
202
+ | `delete` | `(key: string) => boolean` | Removes a single entry. Returns `false` if not found. |
203
+ | `deleteMatching` | `(pattern: string) => number` | Removes all entries matching a glob pattern. Returns the count removed. |
204
+ | `clear` | `() => void` | Removes all entries. |
205
+
206
+ ### Events
207
+
208
+ | Event | Payload | When |
209
+ |-------|---------|------|
210
+ | `set` | `{ type, key, body, statusCode, contentType, expiresAt }` | A response is stored |
211
+ | `delete` | `{ type, key }` | `cache.delete()`, `cache.deleteMatching()`, or `cache.clear()` is called |
212
+ | `expire` | `{ type, key }` | TTL timer fires or lazy expiry is detected |
213
+
214
+ ## Response Headers
215
+
216
+ | Header | Value | Description |
217
+ |--------|-------|-------------|
218
+ | `X-Cache` | `HIT` | Response served from cache |
219
+ | `X-Cache` | `MISS` | Response computed and stored |
220
+
221
+ ## Behavior
222
+
223
+ - Only `GET` requests are cached. All other methods bypass the middleware entirely.
224
+ - Only responses with a `2xx` status code are stored.
225
+ - Each call to `cache()` returns an independent middleware handler, but all handlers created from the same `memorize()` instance **share the same store**.
226
+ - Two separate `memorize()` calls produce **independent stores**.
227
+
228
+ ## License
229
+
230
+ [MIT](LICENSE)
@@ -1,43 +1,95 @@
1
- export interface CacheEntry {
2
- body: unknown;
3
- statusCode: number;
4
- contentType: string;
5
- expiresAt: number | null;
6
- }
7
- export interface CacheInfo extends CacheEntry {
8
- key: string;
9
- remainingTtl: number | null;
10
- }
11
- export interface MemorizeSetEvent {
12
- type: 'set';
13
- key: string;
14
- body: unknown;
15
- statusCode: number;
16
- contentType: string;
17
- expiresAt: number | null;
18
- }
19
- export interface MemorizeDeleteEvent {
20
- type: 'delete';
21
- key: string;
22
- }
23
- export interface MemorizeExpireEvent {
24
- type: 'expire';
25
- key: string;
26
- }
27
- export type MemorizeEvent = MemorizeSetEvent | MemorizeDeleteEvent | MemorizeExpireEvent;
28
- export type MemorizeEventType = MemorizeEvent['type'];
1
+ import { CacheEntry } from './domain/CacheEntry';
2
+ import { CacheInfo } from './domain/CacheInfo';
3
+ import { MemorizeEventType } from './domain/MemorizeEventType';
4
+ import { MemorizeEvent } from './domain/MemorizeEvent';
5
+ import { MemorizeSetEvent } from './domain/MemorizeSetEvent';
6
+ import { MemorizeDeleteEvent } from './domain/MemorizeDeleteEvent';
7
+ import { MemorizeExpireEvent } from './domain/MemorizeExpireEvent';
8
+ import { MemorizeEmptyEvent } from './domain/MemorizeEmptyEvent';
9
+ export type { CacheEntry, CacheInfo, MemorizeEvent, MemorizeSetEvent, MemorizeDeleteEvent, MemorizeExpireEvent, MemorizeEmptyEvent, };
10
+ export { MemorizeEventType };
11
+ /**
12
+ * Low-level in-memory key-value store with optional TTL and event emission.
13
+ *
14
+ * You do not usually interact with this class directly — use the {@link memorize} factory
15
+ * instead, which wraps this store in an Express middleware.
16
+ */
29
17
  export declare class MemorizeStore {
30
18
  private _store;
31
19
  private _timers;
32
20
  private _listeners;
33
- on(event: 'set', handler: (e: MemorizeSetEvent) => void): void;
34
- on(event: 'delete', handler: (e: MemorizeDeleteEvent) => void): void;
35
- on(event: 'expire', handler: (e: MemorizeExpireEvent) => void): void;
21
+ /**
22
+ * Registers an event listener.
23
+ *
24
+ * @param event - The event to listen for.
25
+ * @param handler - Callback invoked with the event payload.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * store.on(MemorizeEventType.Set, (e) => console.log('cached', e.key));
30
+ * store.on(MemorizeEventType.Expire, (e) => console.log('expired', e.key));
31
+ * ```
32
+ */
33
+ on(event: MemorizeEventType.Set, handler: (e: MemorizeSetEvent) => void): void;
34
+ on(event: MemorizeEventType.Delete, handler: (e: MemorizeDeleteEvent) => void): void;
35
+ on(event: MemorizeEventType.Expire, handler: (e: MemorizeExpireEvent) => void): void;
36
+ on(event: MemorizeEventType.Empty, handler: (e: MemorizeEmptyEvent) => void): void;
37
+ /**
38
+ * Stores an entry in the cache.
39
+ *
40
+ * If an entry already exists for the given key its TTL timer is reset and the
41
+ * value is overwritten. Emits a {@link MemorizeEventType.Set} event.
42
+ *
43
+ * @param key - The cache key (typically `req.originalUrl`).
44
+ * @param entry - The response data to store.
45
+ * @param ttl - Time-to-live in milliseconds. Omit or pass `null` for no expiry.
46
+ */
36
47
  set(key: string, entry: Omit<CacheEntry, 'expiresAt'>, ttl?: number | null): void;
48
+ /**
49
+ * Returns the formatted {@link CacheInfo} for the given key, or `null` if the
50
+ * key does not exist or its TTL has elapsed.
51
+ *
52
+ * @param key - The cache key to look up.
53
+ */
37
54
  get(key: string): CacheInfo | null;
55
+ /**
56
+ * Returns all active (non-expired) cache entries as a key→{@link CacheInfo} map.
57
+ * Expired entries are lazily evicted during this call.
58
+ */
38
59
  getAll(): Record<string, CacheInfo>;
60
+ /**
61
+ * Removes a single entry from the cache. Emits a {@link MemorizeEventType.Delete} event.
62
+ *
63
+ * @param key - The cache key to remove.
64
+ * @returns `true` if the entry existed and was removed, `false` otherwise.
65
+ */
39
66
  delete(key: string): boolean;
67
+ /**
68
+ * Removes all cache entries whose keys match the given glob pattern.
69
+ * Emits a {@link MemorizeEventType.Delete} event for each removed entry.
70
+ *
71
+ * Glob rules:
72
+ * - `*` — matches any character sequence **within** a single path segment (does not cross `/`).
73
+ * - `**` — matches any character sequence **across** path segments (crosses `/`).
74
+ * - `?` — matches any single character except `/`.
75
+ *
76
+ * @param pattern - Glob pattern to match against cache keys.
77
+ * @returns The number of entries removed.
78
+ */
79
+ deleteMatching(pattern: string): number;
80
+ /**
81
+ * Removes all entries from the cache. Emits a {@link MemorizeEventType.Delete} event
82
+ * for each entry.
83
+ */
40
84
  clear(): void;
85
+ /**
86
+ * Returns the raw {@link CacheEntry} for the given key without formatting metadata,
87
+ * or `null` if the entry is missing or expired. Used internally by the middleware
88
+ * to serve cached responses.
89
+ *
90
+ * @param key - The cache key to look up.
91
+ * @internal
92
+ */
41
93
  getRaw(key: string): CacheEntry | null;
42
94
  private _evict;
43
95
  private _emit;
@@ -1 +1 @@
1
- {"version":3,"file":"MemorizeStore.d.ts","sourceRoot":"","sources":["../src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,17 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemorizeStore = void 0;
4
- // --- Store ---
3
+ exports.MemorizeStore = exports.MemorizeEventType = void 0;
4
+ const globToRegex_1 = require("./utils/globToRegex");
5
+ const MemorizeEventType_1 = require("./domain/MemorizeEventType");
6
+ Object.defineProperty(exports, "MemorizeEventType", { enumerable: true, get: function () { return MemorizeEventType_1.MemorizeEventType; } });
7
+ /**
8
+ * Low-level in-memory key-value store with optional TTL and event emission.
9
+ *
10
+ * You do not usually interact with this class directly — use the {@link memorize} factory
11
+ * instead, which wraps this store in an Express middleware.
12
+ */
5
13
  class MemorizeStore {
6
14
  constructor() {
7
15
  this._store = new Map();
8
16
  this._timers = new Map();
9
- this._listeners = { set: [], delete: [], expire: [] };
17
+ this._listeners = {
18
+ [MemorizeEventType_1.MemorizeEventType.Set]: [],
19
+ [MemorizeEventType_1.MemorizeEventType.Delete]: [],
20
+ [MemorizeEventType_1.MemorizeEventType.Expire]: [],
21
+ [MemorizeEventType_1.MemorizeEventType.Empty]: [],
22
+ };
10
23
  }
11
24
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
25
  on(event, handler) {
13
26
  this._listeners[event].push(handler);
14
27
  }
28
+ /**
29
+ * Stores an entry in the cache.
30
+ *
31
+ * If an entry already exists for the given key its TTL timer is reset and the
32
+ * value is overwritten. Emits a {@link MemorizeEventType.Set} event.
33
+ *
34
+ * @param key - The cache key (typically `req.originalUrl`).
35
+ * @param entry - The response data to store.
36
+ * @param ttl - Time-to-live in milliseconds. Omit or pass `null` for no expiry.
37
+ */
15
38
  set(key, entry, ttl) {
16
39
  if (this._timers.has(key)) {
17
40
  clearTimeout(this._timers.get(key));
@@ -20,54 +43,105 @@ class MemorizeStore {
20
43
  const expiresAt = ttl ? Date.now() + ttl : null;
21
44
  const stored = { ...entry, expiresAt };
22
45
  this._store.set(key, stored);
23
- this._emit('set', { type: 'set', key, ...entry, expiresAt });
46
+ this._emit(MemorizeEventType_1.MemorizeEventType.Set, { type: MemorizeEventType_1.MemorizeEventType.Set, key, ...entry, expiresAt });
24
47
  if (ttl) {
25
48
  const timer = setTimeout(() => {
26
- this._evict(key, 'expire');
49
+ this._evict(key, MemorizeEventType_1.MemorizeEventType.Expire);
27
50
  }, ttl);
28
51
  if (typeof timer === 'object' && 'unref' in timer)
29
52
  timer.unref();
30
53
  this._timers.set(key, timer);
31
54
  }
32
55
  }
56
+ /**
57
+ * Returns the formatted {@link CacheInfo} for the given key, or `null` if the
58
+ * key does not exist or its TTL has elapsed.
59
+ *
60
+ * @param key - The cache key to look up.
61
+ */
33
62
  get(key) {
34
63
  const entry = this._store.get(key);
35
64
  if (!entry)
36
65
  return null;
37
66
  if (entry.expiresAt && Date.now() > entry.expiresAt) {
38
- this._evict(key, 'expire');
67
+ this._evict(key, MemorizeEventType_1.MemorizeEventType.Expire);
39
68
  return null;
40
69
  }
41
70
  return this._format(key, entry);
42
71
  }
72
+ /**
73
+ * Returns all active (non-expired) cache entries as a key→{@link CacheInfo} map.
74
+ * Expired entries are lazily evicted during this call.
75
+ */
43
76
  getAll() {
44
77
  const result = {};
45
78
  for (const [key, entry] of this._store) {
46
79
  if (entry.expiresAt && Date.now() > entry.expiresAt) {
47
- this._evict(key, 'expire');
80
+ this._evict(key, MemorizeEventType_1.MemorizeEventType.Expire);
48
81
  continue;
49
82
  }
50
83
  result[key] = this._format(key, entry);
51
84
  }
52
85
  return result;
53
86
  }
87
+ /**
88
+ * Removes a single entry from the cache. Emits a {@link MemorizeEventType.Delete} event.
89
+ *
90
+ * @param key - The cache key to remove.
91
+ * @returns `true` if the entry existed and was removed, `false` otherwise.
92
+ */
54
93
  delete(key) {
55
94
  if (!this._store.has(key))
56
95
  return false;
57
- this._evict(key, 'delete');
96
+ this._evict(key, MemorizeEventType_1.MemorizeEventType.Delete);
58
97
  return true;
59
98
  }
99
+ /**
100
+ * Removes all cache entries whose keys match the given glob pattern.
101
+ * Emits a {@link MemorizeEventType.Delete} event for each removed entry.
102
+ *
103
+ * Glob rules:
104
+ * - `*` — matches any character sequence **within** a single path segment (does not cross `/`).
105
+ * - `**` — matches any character sequence **across** path segments (crosses `/`).
106
+ * - `?` — matches any single character except `/`.
107
+ *
108
+ * @param pattern - Glob pattern to match against cache keys.
109
+ * @returns The number of entries removed.
110
+ */
111
+ deleteMatching(pattern) {
112
+ const regex = (0, globToRegex_1.globToRegex)(pattern);
113
+ let count = 0;
114
+ for (const key of [...this._store.keys()]) {
115
+ if (regex.test(key)) {
116
+ this._evict(key, MemorizeEventType_1.MemorizeEventType.Delete);
117
+ count++;
118
+ }
119
+ }
120
+ return count;
121
+ }
122
+ /**
123
+ * Removes all entries from the cache. Emits a {@link MemorizeEventType.Delete} event
124
+ * for each entry.
125
+ */
60
126
  clear() {
61
127
  for (const key of this._store.keys()) {
62
- this._evict(key, 'delete');
128
+ this._evict(key, MemorizeEventType_1.MemorizeEventType.Delete);
63
129
  }
64
130
  }
131
+ /**
132
+ * Returns the raw {@link CacheEntry} for the given key without formatting metadata,
133
+ * or `null` if the entry is missing or expired. Used internally by the middleware
134
+ * to serve cached responses.
135
+ *
136
+ * @param key - The cache key to look up.
137
+ * @internal
138
+ */
65
139
  getRaw(key) {
66
140
  const entry = this._store.get(key);
67
141
  if (!entry)
68
142
  return null;
69
143
  if (entry.expiresAt && Date.now() > entry.expiresAt) {
70
- this._evict(key, 'expire');
144
+ this._evict(key, MemorizeEventType_1.MemorizeEventType.Expire);
71
145
  return null;
72
146
  }
73
147
  return entry;
@@ -79,6 +153,9 @@ class MemorizeStore {
79
153
  }
80
154
  this._store.delete(key);
81
155
  this._emit(reason, { type: reason, key });
156
+ if (this._store.size === 0) {
157
+ this._emit(MemorizeEventType_1.MemorizeEventType.Empty, { type: MemorizeEventType_1.MemorizeEventType.Empty });
158
+ }
82
159
  }
83
160
  _emit(event, payload) {
84
161
  for (const handler of this._listeners[event]) {
@@ -1 +1 @@
1
- {"version":3,"file":"MemorizeSt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CAAC,KAAK,CAAC,qCAAiB,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,qCAAiB,CAAC,KAAK,EAAE,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,KAAwB,EAAE,OAAsB;QAC5D,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAsC,EAAE,CAAC;YAClF,OAAO,CAAC,OAAO,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IAEO,OAAO,CAAC,GAAW,EAAE,KAAiB;QAC5C,OAAO;YACL,GAAG;YACH,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI;SACjF,CAAC;IACJ,CAAC;CACF;AAjMD,sCAiMC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The raw data stored for a cached response.
3
+ */
4
+ export interface CacheEntry {
5
+ /** The serialized response body, as passed to `res.send()`. */
6
+ body: unknown;
7
+ /** HTTP status code of the cached response (e.g. `200`, `201`). */
8
+ statusCode: number;
9
+ /** Value of the `Content-Type` response header (e.g. `application/json; charset=utf-8`). */
10
+ contentType: string;
11
+ /** Unix timestamp (ms) at which the entry expires, or `null` if it never expires. */
12
+ expiresAt: number | null;
13
+ }
14
+ //# sourceMappingURL=CacheEntry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheEntry.d.ts","sourceRoot":"","sources":["../../src/domain/CacheEntry.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,+DAA+D;IAC/D,IAAI,EAAE,OAAO,CAAC;IACd,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAC;IACnB,4FAA4F;IAC5F,WAAW,EAAE,MAAM,CAAC;IACpB,qFAAqF;IACrF,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=CacheEntry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheEntry.js","sourceRoot":"","sources":["../../src/domain/CacheEntry.ts"],"names":[],"mappings":""}