express-memorize 1.0.0 → 1.2.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 (64) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/LICENSE +21 -0
  3. package/README.md +201 -0
  4. package/dist/MemorizeStore.d.ts +70 -31
  5. package/dist/MemorizeStore.d.ts.map +1 -1
  6. package/dist/MemorizeStore.js +63 -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 +123 -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 +18 -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 +51 -0
  63. package/dist/memorize.js.map +1 -1
  64. package/package.json +30 -6
package/CHANGELOG.md ADDED
@@ -0,0 +1,45 @@
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.2.0](https://github.com/ElJijuna/express-memorize/compare/v1.1.0...v1.2.0) (2026-03-24)
8
+
9
+
10
+ ### Features
11
+
12
+ * 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))
13
+
14
+ ## [1.1.0](https://github.com/ElJijuna/express-memorize/compare/v1.0.0...v1.1.0) (2026-03-24)
15
+
16
+
17
+ ### Features
18
+
19
+ * add evento to notify when cache is empty. ([8484f29](https://github.com/ElJijuna/express-memorize/commit/8484f29f1d1f2bd275970a0c02fa9b64a46576b9))
20
+
21
+ ## 1.0.0 (2026-03-24)
22
+
23
+
24
+ ### Features
25
+
26
+ * add events to log activity in memory store. ([5b3905b](https://github.com/ElJijuna/express-memorize/commit/5b3905b898a5d91c4c61510dd5d8c92eabf096e9))
27
+ * add github action to publish in NPM ([7f79eca](https://github.com/ElJijuna/express-memorize/commit/7f79eca766356280f677411b166c8e2608140d16))
28
+ * add middleware to use memorize. ([73a02a0](https://github.com/ElJijuna/express-memorize/commit/73a02a096750ec66bb8d9c183b0f07c2aeb3cd83))
29
+ * add tests and express client to execute local implementation. ([75d3cf8](https://github.com/ElJijuna/express-memorize/commit/75d3cf81f979a04ef9f0964a444e2966a2ba8164))
30
+ * add validation to only add to store GET methods in middleware. ([04e2918](https://github.com/ElJijuna/express-memorize/commit/04e291884ab083321838cca40755e2c02e98ec6c))
31
+
32
+ ## [1.0.0] - 2026-03-24
33
+
34
+ ### Features
35
+
36
+ - In-memory cache middleware for Express.js
37
+ - Key-value store using full request path (`originalUrl`) as key
38
+ - TTL support with automatic expiry via `setTimeout`
39
+ - Per-route TTL override
40
+ - Caches only `GET` requests with `2xx` status codes
41
+ - `Content-Type` preservation on cache hits
42
+ - `X-Cache: HIT | MISS` response header
43
+ - Cache management API: `get`, `getAll`, `delete`, `clear`
44
+ - Event system: `set`, `delete`, `expire` hooks
45
+ - 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,201 @@
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
+ ### Event hooks
106
+
107
+ ```typescript
108
+ const cache = memorize({ ttl: 30_000 });
109
+
110
+ cache.on('set', (e) => {
111
+ console.log(`[cache] stored ${e.key} — expires in ${e.expiresAt ? e.expiresAt - Date.now() : '∞'}ms`);
112
+ });
113
+
114
+ cache.on('delete', (e) => {
115
+ console.log(`[cache] deleted ${e.key}`);
116
+ });
117
+
118
+ cache.on('expire', (e) => {
119
+ console.log(`[cache] expired ${e.key}`);
120
+ });
121
+ ```
122
+
123
+ ### Inspect the cache
124
+
125
+ ```typescript
126
+ cache.get('/users'); // CacheInfo | null — single entry
127
+ cache.getAll(); // Record<string, CacheInfo> — all active entries
128
+ ```
129
+
130
+ `CacheInfo` shape:
131
+
132
+ ```typescript
133
+ {
134
+ key: string;
135
+ body: unknown;
136
+ statusCode: number;
137
+ contentType: string;
138
+ expiresAt: number | null;
139
+ remainingTtl: number | null; // ms until expiry, null if no TTL
140
+ }
141
+ ```
142
+
143
+ ### Clear the cache
144
+
145
+ ```typescript
146
+ cache.delete('/users'); // remove one entry
147
+ cache.clear(); // remove all entries
148
+ ```
149
+
150
+ ## API Reference
151
+
152
+ ### `memorize(options?)`
153
+
154
+ Creates a cache instance. Returns a `Memorize` object.
155
+
156
+ | Option | Type | Default | Description |
157
+ |--------|------|---------|-------------|
158
+ | `ttl` | `number` | `undefined` | Time-to-live in milliseconds. Omit for no expiry. |
159
+
160
+ ### `cache(options?)`
161
+
162
+ Returns an Express `RequestHandler` middleware. Can override the global TTL.
163
+
164
+ | Option | Type | Default | Description |
165
+ |--------|------|---------|-------------|
166
+ | `ttl` | `number` | global `ttl` | TTL override for this specific route. |
167
+
168
+ ### Cache management
169
+
170
+ | Method | Signature | Description |
171
+ |--------|-----------|-------------|
172
+ | `get` | `(key: string) => CacheInfo \| null` | Returns info for a cached key. |
173
+ | `getAll` | `() => Record<string, CacheInfo>` | Returns all active cache entries. |
174
+ | `delete` | `(key: string) => boolean` | Removes a single entry. Returns `false` if not found. |
175
+ | `clear` | `() => void` | Removes all entries. |
176
+
177
+ ### Events
178
+
179
+ | Event | Payload | When |
180
+ |-------|---------|------|
181
+ | `set` | `{ type, key, body, statusCode, contentType, expiresAt }` | A response is stored |
182
+ | `delete` | `{ type, key }` | `cache.delete()` or `cache.clear()` is called |
183
+ | `expire` | `{ type, key }` | TTL timer fires or lazy expiry is detected |
184
+
185
+ ## Response Headers
186
+
187
+ | Header | Value | Description |
188
+ |--------|-------|-------------|
189
+ | `X-Cache` | `HIT` | Response served from cache |
190
+ | `X-Cache` | `MISS` | Response computed and stored |
191
+
192
+ ## Behavior
193
+
194
+ - Only `GET` requests are cached. All other methods bypass the middleware entirely.
195
+ - Only responses with a `2xx` status code are stored.
196
+ - Each call to `cache()` returns an independent middleware handler, but all handlers created from the same `memorize()` instance **share the same store**.
197
+ - Two separate `memorize()` calls produce **independent stores**.
198
+
199
+ ## License
200
+
201
+ [MIT](LICENSE)
@@ -1,43 +1,82 @@
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 entries from the cache. Emits a {@link MemorizeEventType.Delete} event
69
+ * for each entry.
70
+ */
40
71
  clear(): void;
72
+ /**
73
+ * Returns the raw {@link CacheEntry} for the given key without formatting metadata,
74
+ * or `null` if the entry is missing or expired. Used internally by the middleware
75
+ * to serve cached responses.
76
+ *
77
+ * @param key - The cache key to look up.
78
+ * @internal
79
+ */
41
80
  getRaw(key: string): CacheEntry | null;
42
81
  private _evict;
43
82
  private _emit;
@@ -1 +1 @@
1
- {"version":3,"file":"MemorizeStore.d.ts","sourceRoot":"","sources":["../src/MemorizeStore.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WA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AAI,GAAG,IAAI;IACjF,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,mBAAmB,KAAK,IAAI,GAAG,IAAI;IACpF,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,mBAAmB,KAAK,IAAI,GAAG,IAAI;IACpF,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,KAAK,EAAG,OAAO,EAAE,CAAC,CAAC,EAAE,kBAAkB,KAAK,IAAI,GAAG,IAAI;IAMnF;;;;;;;;;OASG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAsBjF;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAYlC;;;OAGG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IAcnC;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAM5B;;;OAGG;IACH,KAAK,IAAI,IAAI;IAMb;;;;;;;OAOG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAYtC,OAAO,CAAC,MAAM;IAYd,OAAO,CAAC,KAAK;IAMb,OAAO,CAAC,OAAO;CAUhB"}
@@ -1,17 +1,39 @@
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 MemorizeEventType_1 = require("./domain/MemorizeEventType");
5
+ Object.defineProperty(exports, "MemorizeEventType", { enumerable: true, get: function () { return MemorizeEventType_1.MemorizeEventType; } });
6
+ /**
7
+ * Low-level in-memory key-value store with optional TTL and event emission.
8
+ *
9
+ * You do not usually interact with this class directly — use the {@link memorize} factory
10
+ * instead, which wraps this store in an Express middleware.
11
+ */
5
12
  class MemorizeStore {
6
13
  constructor() {
7
14
  this._store = new Map();
8
15
  this._timers = new Map();
9
- this._listeners = { set: [], delete: [], expire: [] };
16
+ this._listeners = {
17
+ [MemorizeEventType_1.MemorizeEventType.Set]: [],
18
+ [MemorizeEventType_1.MemorizeEventType.Delete]: [],
19
+ [MemorizeEventType_1.MemorizeEventType.Expire]: [],
20
+ [MemorizeEventType_1.MemorizeEventType.Empty]: [],
21
+ };
10
22
  }
11
23
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
24
  on(event, handler) {
13
25
  this._listeners[event].push(handler);
14
26
  }
27
+ /**
28
+ * Stores an entry in the cache.
29
+ *
30
+ * If an entry already exists for the given key its TTL timer is reset and the
31
+ * value is overwritten. Emits a {@link MemorizeEventType.Set} event.
32
+ *
33
+ * @param key - The cache key (typically `req.originalUrl`).
34
+ * @param entry - The response data to store.
35
+ * @param ttl - Time-to-live in milliseconds. Omit or pass `null` for no expiry.
36
+ */
15
37
  set(key, entry, ttl) {
16
38
  if (this._timers.has(key)) {
17
39
  clearTimeout(this._timers.get(key));
@@ -20,54 +42,82 @@ class MemorizeStore {
20
42
  const expiresAt = ttl ? Date.now() + ttl : null;
21
43
  const stored = { ...entry, expiresAt };
22
44
  this._store.set(key, stored);
23
- this._emit('set', { type: 'set', key, ...entry, expiresAt });
45
+ this._emit(MemorizeEventType_1.MemorizeEventType.Set, { type: MemorizeEventType_1.MemorizeEventType.Set, key, ...entry, expiresAt });
24
46
  if (ttl) {
25
47
  const timer = setTimeout(() => {
26
- this._evict(key, 'expire');
48
+ this._evict(key, MemorizeEventType_1.MemorizeEventType.Expire);
27
49
  }, ttl);
28
50
  if (typeof timer === 'object' && 'unref' in timer)
29
51
  timer.unref();
30
52
  this._timers.set(key, timer);
31
53
  }
32
54
  }
55
+ /**
56
+ * Returns the formatted {@link CacheInfo} for the given key, or `null` if the
57
+ * key does not exist or its TTL has elapsed.
58
+ *
59
+ * @param key - The cache key to look up.
60
+ */
33
61
  get(key) {
34
62
  const entry = this._store.get(key);
35
63
  if (!entry)
36
64
  return null;
37
65
  if (entry.expiresAt && Date.now() > entry.expiresAt) {
38
- this._evict(key, 'expire');
66
+ this._evict(key, MemorizeEventType_1.MemorizeEventType.Expire);
39
67
  return null;
40
68
  }
41
69
  return this._format(key, entry);
42
70
  }
71
+ /**
72
+ * Returns all active (non-expired) cache entries as a key→{@link CacheInfo} map.
73
+ * Expired entries are lazily evicted during this call.
74
+ */
43
75
  getAll() {
44
76
  const result = {};
45
77
  for (const [key, entry] of this._store) {
46
78
  if (entry.expiresAt && Date.now() > entry.expiresAt) {
47
- this._evict(key, 'expire');
79
+ this._evict(key, MemorizeEventType_1.MemorizeEventType.Expire);
48
80
  continue;
49
81
  }
50
82
  result[key] = this._format(key, entry);
51
83
  }
52
84
  return result;
53
85
  }
86
+ /**
87
+ * Removes a single entry from the cache. Emits a {@link MemorizeEventType.Delete} event.
88
+ *
89
+ * @param key - The cache key to remove.
90
+ * @returns `true` if the entry existed and was removed, `false` otherwise.
91
+ */
54
92
  delete(key) {
55
93
  if (!this._store.has(key))
56
94
  return false;
57
- this._evict(key, 'delete');
95
+ this._evict(key, MemorizeEventType_1.MemorizeEventType.Delete);
58
96
  return true;
59
97
  }
98
+ /**
99
+ * Removes all entries from the cache. Emits a {@link MemorizeEventType.Delete} event
100
+ * for each entry.
101
+ */
60
102
  clear() {
61
103
  for (const key of this._store.keys()) {
62
- this._evict(key, 'delete');
104
+ this._evict(key, MemorizeEventType_1.MemorizeEventType.Delete);
63
105
  }
64
106
  }
107
+ /**
108
+ * Returns the raw {@link CacheEntry} for the given key without formatting metadata,
109
+ * or `null` if the entry is missing or expired. Used internally by the middleware
110
+ * to serve cached responses.
111
+ *
112
+ * @param key - The cache key to look up.
113
+ * @internal
114
+ */
65
115
  getRaw(key) {
66
116
  const entry = this._store.get(key);
67
117
  if (!entry)
68
118
  return null;
69
119
  if (entry.expiresAt && Date.now() > entry.expiresAt) {
70
- this._evict(key, 'expire');
120
+ this._evict(key, MemorizeEventType_1.MemorizeEventType.Expire);
71
121
  return null;
72
122
  }
73
123
  return entry;
@@ -79,6 +129,9 @@ class MemorizeStore {
79
129
  }
80
130
  this._store.delete(key);
81
131
  this._emit(reason, { type: reason, key });
132
+ if (this._store.size === 0) {
133
+ this._emit(MemorizeEventType_1.MemorizeEventType.Empty, { type: MemorizeEventType_1.MemorizeEventType.Empty });
134
+ }
82
135
  }
83
136
  _emit(event, payload) {
84
137
  for (const handler of this._listeners[event]) {
@@ -1 +1 @@
1
- {"version":3,"file":"MemorizeStore.js","sourceRoot":"","sources":["../src/MemorizeStore.ts"],"names":[],"mappings":";;;AAyCA,gBAAgB;AAEhB,MAAa,aAAa;IAA1B;QACU,WAAM,GAAG,IAAI,GAAG,EAAsB,CAAC;QACvC,YAAO,GAAG,IAAI,GAAG,EAAyC,CAAC;QAC3D,eAAU,GAAgB,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IA2GxE,CAAC;IAtGC,8DAA8D;IAC9D,EAAE,CAAC,KAAwB,EAAE,OAAyB;QACpD,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAoC,EAAE,GAAmB;QACxE,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,CAAC;YACrC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;QAED,MAAM,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG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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;AAzKD,sCAyKC"}
@@ -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":""}
@@ -0,0 +1,12 @@
1
+ import { CacheEntry } from './CacheEntry';
2
+ /**
3
+ * A cache entry enriched with lookup metadata, returned by {@link Memorize.get} and
4
+ * {@link Memorize.getAll}.
5
+ */
6
+ export interface CacheInfo extends CacheEntry {
7
+ /** The cache key — the full request path including query string (e.g. `/users?page=1`). */
8
+ key: string;
9
+ /** Milliseconds remaining until the entry expires. `null` if the entry has no TTL. */
10
+ remainingTtl: number | null;
11
+ }
12
+ //# sourceMappingURL=CacheInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheInfo.d.ts","sourceRoot":"","sources":["../../src/domain/CacheInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,UAAU;IAC3C,2FAA2F;IAC3F,GAAG,EAAE,MAAM,CAAC;IACZ,sFAAsF;IACtF,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=CacheInfo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheInfo.js","sourceRoot":"","sources":["../../src/domain/CacheInfo.ts"],"names":[],"mappings":""}