express-memorize 2.1.0 → 2.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.
- package/CHANGELOG.md +8 -0
- package/README.md +111 -2
- package/dist/adapters/fastify.d.ts +40 -0
- package/dist/adapters/fastify.d.ts.map +1 -0
- package/dist/adapters/fastify.js +93 -0
- package/dist/adapters/fastify.js.map +1 -0
- package/dist/adapters/koa.d.ts +36 -0
- package/dist/adapters/koa.d.ts.map +1 -0
- package/dist/adapters/koa.js +73 -0
- package/dist/adapters/koa.js.map +1 -0
- package/dist/domain/Memorize.d.ts +6 -0
- package/dist/domain/Memorize.d.ts.map +1 -1
- package/dist/memorize.d.ts.map +1 -1
- package/dist/memorize.js +1 -0
- package/dist/memorize.js.map +1 -1
- package/package.json +25 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# [2.2.0](https://github.com/ElJijuna/express-memorize/compare/v2.1.0...v2.2.0) (2026-05-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **fastify:** add Fastify cache adapter (Closes [#9](https://github.com/ElJijuna/express-memorize/issues/9)) ([9b940cd](https://github.com/ElJijuna/express-memorize/commit/9b940cdc4a15c27d17264a497c29d32bde09e523))
|
|
7
|
+
* **koa:** add Koa cache adapter (Closes [#8](https://github.com/ElJijuna/express-memorize/issues/8)) ([39673fc](https://github.com/ElJijuna/express-memorize/commit/39673fcd92b5cb5d57560adb982cf1d4b85d4eb5))
|
|
8
|
+
|
|
1
9
|
# [2.1.0](https://github.com/ElJijuna/express-memorize/compare/v2.0.0...v2.1.0) (2026-05-11)
|
|
2
10
|
|
|
3
11
|
|
package/README.md
CHANGED
|
@@ -9,16 +9,25 @@
|
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
12
|
-
In-memory HTTP cache for <strong>Express, NestJS, Hono, Fetch API</strong>, and more.<br/>
|
|
12
|
+
In-memory HTTP cache for <strong>Express, Fastify, Koa, NestJS, Hono, Fetch API</strong>, and more.<br/>
|
|
13
13
|
Caches <code>GET</code> responses with optional TTL — zero dependencies, fully typed.
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="#express"><img src="https://img.shields.io/badge/Express-000000?logo=express&logoColor=white" alt="Express adapter" /></a>
|
|
18
|
+
<a href="#fastify"><img src="https://img.shields.io/badge/Fastify-000000?logo=fastify&logoColor=white" alt="Fastify adapter" /></a>
|
|
19
|
+
<a href="#koa"><img src="https://img.shields.io/badge/Koa-33333D?logo=koa&logoColor=white" alt="Koa adapter" /></a>
|
|
20
|
+
<a href="#nestjs"><img src="https://img.shields.io/badge/NestJS-E0234E?logo=nestjs&logoColor=white" alt="NestJS adapter" /></a>
|
|
21
|
+
<a href="#hono"><img src="https://img.shields.io/badge/Hono-E36002?logo=hono&logoColor=white" alt="Hono adapter" /></a>
|
|
22
|
+
<a href="#fetch-api--serverless"><img src="https://img.shields.io/badge/Fetch%20API-F7DF1E?logo=javascript&logoColor=black" alt="Fetch API adapter" /></a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
16
25
|
---
|
|
17
26
|
|
|
18
27
|
## Features
|
|
19
28
|
|
|
20
29
|
- Caches `GET` responses automatically when status code is `2xx`
|
|
21
|
-
- Works with **Express**, **NestJS**, **Hono**, **Fetch API / serverless**, and direct service-level usage
|
|
30
|
+
- Works with **Express**, **Fastify**, **Koa**, **NestJS**, **Hono**, **Fetch API / serverless**, and direct service-level usage
|
|
22
31
|
- Per-route TTL override and `noCache` bypass
|
|
23
32
|
- **`maxEntries` cap with LRU eviction** to bound memory usage
|
|
24
33
|
- **Size metrics**: `size()`, `byteSize()`, `getStats()`
|
|
@@ -38,6 +47,8 @@ npm install express-memorize
|
|
|
38
47
|
Adapters for non-Express runtimes are optional — install only what you need:
|
|
39
48
|
|
|
40
49
|
```bash
|
|
50
|
+
npm install fastify # only if using the Fastify adapter
|
|
51
|
+
npm install koa @koa/router # only if using the Koa adapter
|
|
41
52
|
npm install hono # only if using the Hono adapter
|
|
42
53
|
npm install @nestjs/common @nestjs/core rxjs # only if using the NestJS adapter
|
|
43
54
|
```
|
|
@@ -61,6 +72,43 @@ app.get('/users', cache(), async (req, res) => {
|
|
|
61
72
|
app.listen(3000);
|
|
62
73
|
```
|
|
63
74
|
|
|
75
|
+
### Fastify
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import Fastify from 'fastify';
|
|
79
|
+
import { memorize } from 'express-memorize';
|
|
80
|
+
import { createFastifyPlugin } from 'express-memorize/fastify';
|
|
81
|
+
|
|
82
|
+
const app = Fastify();
|
|
83
|
+
const cache = memorize({ ttl: 30_000 });
|
|
84
|
+
|
|
85
|
+
await app.register(createFastifyPlugin(cache));
|
|
86
|
+
|
|
87
|
+
app.get('/users', async () => {
|
|
88
|
+
return usersService.findAll();
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Koa
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import Koa from 'koa';
|
|
96
|
+
import Router from '@koa/router';
|
|
97
|
+
import { memorize } from 'express-memorize';
|
|
98
|
+
import { createKoaMiddleware } from 'express-memorize/koa';
|
|
99
|
+
|
|
100
|
+
const app = new Koa();
|
|
101
|
+
const router = new Router();
|
|
102
|
+
const cache = memorize({ ttl: 30_000 });
|
|
103
|
+
|
|
104
|
+
router.get('/users', createKoaMiddleware(cache), async (ctx) => {
|
|
105
|
+
ctx.body = await usersService.findAll();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
app.use(router.routes());
|
|
109
|
+
app.use(router.allowedMethods());
|
|
110
|
+
```
|
|
111
|
+
|
|
64
112
|
### Hono
|
|
65
113
|
|
|
66
114
|
```typescript
|
|
@@ -166,6 +214,65 @@ app.get('/live-feed', cache({ noCache: true }), handler);
|
|
|
166
214
|
// Sets X-Cache: BYPASS, never reads or writes the cache
|
|
167
215
|
```
|
|
168
216
|
|
|
217
|
+
### Fastify route-level usage
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
import { createFastifyPreHandler } from 'express-memorize/fastify';
|
|
221
|
+
|
|
222
|
+
app.get(
|
|
223
|
+
'/users',
|
|
224
|
+
{
|
|
225
|
+
preHandler: createFastifyPreHandler(cache, { ttl: 10_000 }),
|
|
226
|
+
},
|
|
227
|
+
async () => usersService.findAll(),
|
|
228
|
+
);
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### GraphQL caching
|
|
232
|
+
|
|
233
|
+
GraphQL is not a simple route-level caching problem. A single `POST /graphql`
|
|
234
|
+
endpoint can execute different operations, use variables, depend on the current
|
|
235
|
+
viewer, and return partial data with errors. For now, the recommended strategy
|
|
236
|
+
is **service-level caching** with `remember()` inside resolvers or the services
|
|
237
|
+
they call.
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
const cache = memorize({ ttl: 30_000 });
|
|
241
|
+
|
|
242
|
+
const resolvers = {
|
|
243
|
+
Query: {
|
|
244
|
+
user: (_parent, args, context) => {
|
|
245
|
+
const viewerScope = context.user ? `user:${context.user.id}` : 'anonymous';
|
|
246
|
+
return cache.remember(
|
|
247
|
+
`graphql:${viewerScope}:user:${args.id}`,
|
|
248
|
+
() => usersService.findVisibleById(args.id, context.user),
|
|
249
|
+
);
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
Mutation: {
|
|
253
|
+
updateUser: async (_parent, args) => {
|
|
254
|
+
const user = await usersService.update(args.id, args.input);
|
|
255
|
+
cache.deleteMatching(`graphql:*:user:${args.id}`);
|
|
256
|
+
return user;
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**GraphQL cache key rules:**
|
|
263
|
+
|
|
264
|
+
- Include every input that can change the result: operation name, normalized query or field name, variables, locale, feature flags, and any relevant authorization scope.
|
|
265
|
+
- Do not share cached data across users unless the resolver result is genuinely public.
|
|
266
|
+
- Keep mutation invalidation explicit with `delete()` or `deleteMatching()`; automatic invalidation is too schema-specific for a generic adapter.
|
|
267
|
+
- Avoid caching responses that contain GraphQL errors unless your application has a deliberate policy for partial data.
|
|
268
|
+
- Prefer resolver or service-level caching for expensive data fetches. Operation-level caching may be considered later for public, query-only workloads with strict keying rules.
|
|
269
|
+
|
|
270
|
+
There is currently no dedicated GraphQL adapter. If one is added later, the
|
|
271
|
+
first practical target should be **Apollo Server**, because its plugin lifecycle
|
|
272
|
+
can cache complete operation responses without coupling the core package entry
|
|
273
|
+
point to GraphQL. NestJS GraphQL, Mercurius, and Yoga integrations should stay
|
|
274
|
+
separate implementation issues unless a shared GraphQL abstraction emerges.
|
|
275
|
+
|
|
169
276
|
### NestJS decorators
|
|
170
277
|
|
|
171
278
|
Use `MemorizeInterceptor` on a controller or globally, then configure caching at the controller or method level.
|
|
@@ -333,6 +440,8 @@ Returns an Express `RequestHandler`. `cache()` is a backwards-compatible alias f
|
|
|
333
440
|
|-------------|--------|-----------|
|
|
334
441
|
| `express-memorize` | `memorize` | Core factory |
|
|
335
442
|
| `express-memorize/express` | `createExpressAdapter(cache, options?)` | Express |
|
|
443
|
+
| `express-memorize/fastify` | `createFastifyPlugin(cache, options?)`, `createFastifyPreHandler(cache, options?)` | Fastify |
|
|
444
|
+
| `express-memorize/koa` | `createKoaMiddleware(cache, options?)` | Koa |
|
|
336
445
|
| `express-memorize/nestjs` | `MemorizeModule`, `MemorizeInterceptor`, decorators | NestJS |
|
|
337
446
|
| `express-memorize/hono` | `createHonoMiddleware(cache, options?)` | Hono |
|
|
338
447
|
| `express-memorize/fetch` | `cacheFetchHandler(cache, handler, options?)` | Fetch API / Serverless |
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { FastifyPluginCallback, FastifyRequest, preHandlerHookHandler } from 'fastify';
|
|
2
|
+
import type { Memorize } from '../domain/Memorize';
|
|
3
|
+
export interface FastifyAdapterOptions {
|
|
4
|
+
/** Time-to-live in milliseconds. Defaults to the global TTL. */
|
|
5
|
+
ttl?: number;
|
|
6
|
+
/** Skip caching for this route. Sets `X-Cache: BYPASS`. */
|
|
7
|
+
noCache?: boolean;
|
|
8
|
+
/** Custom cache key extractor. Defaults to `request.url`. */
|
|
9
|
+
key?: (request: FastifyRequest) => string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a Fastify plugin that caches `GET` route responses with a `2xx`
|
|
13
|
+
* status code.
|
|
14
|
+
*
|
|
15
|
+
* Requires `fastify` to be installed as an optional peer dependency.
|
|
16
|
+
*
|
|
17
|
+
* @param cache - The {@link Memorize} instance to use as the backing store.
|
|
18
|
+
* @param options - Optional plugin-level options.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import Fastify from 'fastify';
|
|
23
|
+
* import { memorize } from 'express-memorize';
|
|
24
|
+
* import { createFastifyPlugin } from 'express-memorize/fastify';
|
|
25
|
+
*
|
|
26
|
+
* const app = Fastify();
|
|
27
|
+
* const cache = memorize({ ttl: 30_000 });
|
|
28
|
+
*
|
|
29
|
+
* await app.register(createFastifyPlugin(cache));
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function createFastifyPlugin(cache: Memorize, options?: FastifyAdapterOptions): FastifyPluginCallback;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a route-level Fastify `preHandler` that caches `GET` responses.
|
|
35
|
+
*
|
|
36
|
+
* Use this when only selected routes should be cached, or when a route needs a
|
|
37
|
+
* TTL, `noCache`, or key override.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createFastifyPreHandler(cache: Memorize, options?: FastifyAdapterOptions): preHandlerHookHandler;
|
|
40
|
+
//# sourceMappingURL=fastify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../../src/adapters/fastify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAErB,cAAc,EACd,qBAAqB,EACtB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,WAAW,qBAAqB;IACpC,gEAAgE;IAChE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,6DAA6D;IAC7D,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,MAAM,CAAC;CAC3C;AAmBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,QAAQ,EACf,OAAO,CAAC,EAAE,qBAAqB,GAC9B,qBAAqB,CAavB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,QAAQ,EACf,OAAO,CAAC,EAAE,qBAAqB,GAC9B,qBAAqB,CAkDvB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFastifyPlugin = createFastifyPlugin;
|
|
4
|
+
exports.createFastifyPreHandler = createFastifyPreHandler;
|
|
5
|
+
function serializePayload(payload) {
|
|
6
|
+
if (typeof payload === 'string' ||
|
|
7
|
+
Buffer.isBuffer(payload) ||
|
|
8
|
+
payload instanceof ArrayBuffer ||
|
|
9
|
+
ArrayBuffer.isView(payload)) {
|
|
10
|
+
return { body: payload };
|
|
11
|
+
}
|
|
12
|
+
if (payload === undefined) {
|
|
13
|
+
return { body: '' };
|
|
14
|
+
}
|
|
15
|
+
return { body: JSON.stringify(payload), contentType: 'application/json; charset=utf-8' };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a Fastify plugin that caches `GET` route responses with a `2xx`
|
|
19
|
+
* status code.
|
|
20
|
+
*
|
|
21
|
+
* Requires `fastify` to be installed as an optional peer dependency.
|
|
22
|
+
*
|
|
23
|
+
* @param cache - The {@link Memorize} instance to use as the backing store.
|
|
24
|
+
* @param options - Optional plugin-level options.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import Fastify from 'fastify';
|
|
29
|
+
* import { memorize } from 'express-memorize';
|
|
30
|
+
* import { createFastifyPlugin } from 'express-memorize/fastify';
|
|
31
|
+
*
|
|
32
|
+
* const app = Fastify();
|
|
33
|
+
* const cache = memorize({ ttl: 30_000 });
|
|
34
|
+
*
|
|
35
|
+
* await app.register(createFastifyPlugin(cache));
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function createFastifyPlugin(cache, options) {
|
|
39
|
+
const plugin = function memorizeFastifyPlugin(fastify, _pluginOptions, done) {
|
|
40
|
+
fastify.addHook('preHandler', createFastifyPreHandler(cache, options));
|
|
41
|
+
done();
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperties(plugin, {
|
|
44
|
+
[Symbol.for('skip-override')]: { value: true },
|
|
45
|
+
[Symbol.for('fastify.display-name')]: { value: 'express-memorize-fastify' },
|
|
46
|
+
[Symbol.for('plugin-meta')]: { value: { name: 'express-memorize-fastify' } },
|
|
47
|
+
});
|
|
48
|
+
return plugin;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a route-level Fastify `preHandler` that caches `GET` responses.
|
|
52
|
+
*
|
|
53
|
+
* Use this when only selected routes should be cached, or when a route needs a
|
|
54
|
+
* TTL, `noCache`, or key override.
|
|
55
|
+
*/
|
|
56
|
+
function createFastifyPreHandler(cache, options) {
|
|
57
|
+
return function memorizeFastifyPreHandler(request, reply, done) {
|
|
58
|
+
if (request.method !== 'GET') {
|
|
59
|
+
done();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (options === null || options === void 0 ? void 0 : options.noCache) {
|
|
63
|
+
reply.header('X-Cache', 'BYPASS');
|
|
64
|
+
done();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const key = (options === null || options === void 0 ? void 0 : options.key) ? options.key(request) : request.url;
|
|
68
|
+
const cached = cache._store.getRaw(key);
|
|
69
|
+
if (cached) {
|
|
70
|
+
reply
|
|
71
|
+
.header('X-Cache', 'HIT')
|
|
72
|
+
.type(cached.contentType)
|
|
73
|
+
.code(cached.statusCode)
|
|
74
|
+
.send(cached.body);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const originalSend = reply.send.bind(reply);
|
|
78
|
+
reply.send = function sendWithCache(payload) {
|
|
79
|
+
var _a, _b, _c, _d;
|
|
80
|
+
const statusCode = reply.statusCode;
|
|
81
|
+
if (statusCode >= 200 && statusCode < 300) {
|
|
82
|
+
const ttl = (_a = options === null || options === void 0 ? void 0 : options.ttl) !== null && _a !== void 0 ? _a : cache._ttl;
|
|
83
|
+
const serialized = serializePayload(payload);
|
|
84
|
+
const contentType = (_d = (_c = (_b = reply.getHeader('content-type')) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : serialized.contentType) !== null && _d !== void 0 ? _d : 'application/octet-stream';
|
|
85
|
+
cache._store.set(key, { body: serialized.body, statusCode, contentType }, ttl);
|
|
86
|
+
}
|
|
87
|
+
reply.header('X-Cache', 'MISS');
|
|
88
|
+
return originalSend(payload);
|
|
89
|
+
};
|
|
90
|
+
done();
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=fastify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../../src/adapters/fastify.ts"],"names":[],"mappings":";;AAuDA,kDAgBC;AAQD,0DAqDC;AAnHD,SAAS,gBAAgB,CAAC,OAAgB;IACxC,IACE,OAAO,OAAO,KAAK,QAAQ;QAC3B,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QACxB,OAAO,YAAY,WAAW;QAC9B,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,EAC3B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CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,GAAG,CAAC,CAAC;YACjF,CAAC;YAED,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAChC,OAAO,YAAY,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC,CAAC;QAEF,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Context, Middleware } from 'koa';
|
|
2
|
+
import type { Memorize } from '../domain/Memorize';
|
|
3
|
+
export interface KoaAdapterOptions {
|
|
4
|
+
/** Time-to-live in milliseconds. Defaults to the global TTL. */
|
|
5
|
+
ttl?: number;
|
|
6
|
+
/** Skip caching for this route. Sets `X-Cache: BYPASS`. */
|
|
7
|
+
noCache?: boolean;
|
|
8
|
+
/** Custom cache key extractor. Defaults to `ctx.originalUrl ?? ctx.url`. */
|
|
9
|
+
key?: (ctx: Context) => string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates Koa middleware that caches `GET` responses with a `2xx` status code.
|
|
13
|
+
*
|
|
14
|
+
* Requires `koa` to be installed as an optional peer dependency.
|
|
15
|
+
*
|
|
16
|
+
* @param cache - The {@link Memorize} instance to use as the backing store.
|
|
17
|
+
* @param options - Optional per-route options.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import Koa from 'koa';
|
|
22
|
+
* import Router from '@koa/router';
|
|
23
|
+
* import { memorize } from 'express-memorize';
|
|
24
|
+
* import { createKoaMiddleware } from 'express-memorize/koa';
|
|
25
|
+
*
|
|
26
|
+
* const app = new Koa();
|
|
27
|
+
* const router = new Router();
|
|
28
|
+
* const cache = memorize({ ttl: 30_000 });
|
|
29
|
+
*
|
|
30
|
+
* router.get('/users', createKoaMiddleware(cache), async (ctx) => {
|
|
31
|
+
* ctx.body = await usersService.findAll();
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function createKoaMiddleware(cache: Memorize, options?: KoaAdapterOptions): Middleware;
|
|
36
|
+
//# sourceMappingURL=koa.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"koa.d.ts","sourceRoot":"","sources":["../../src/adapters/koa.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,WAAW,iBAAiB;IAChC,gEAAgE;IAChE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,4EAA4E;IAC5E,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;CAChC;AAsBD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,QAAQ,EACf,OAAO,CAAC,EAAE,iBAAiB,GAC1B,UAAU,CAoCZ"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createKoaMiddleware = createKoaMiddleware;
|
|
4
|
+
function defaultKey(ctx) {
|
|
5
|
+
var _a;
|
|
6
|
+
return (_a = ctx.originalUrl) !== null && _a !== void 0 ? _a : ctx.url;
|
|
7
|
+
}
|
|
8
|
+
function inferContentType(body) {
|
|
9
|
+
if (Buffer.isBuffer(body) || body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {
|
|
10
|
+
return 'application/octet-stream';
|
|
11
|
+
}
|
|
12
|
+
if (typeof body === 'string') {
|
|
13
|
+
return 'text/plain';
|
|
14
|
+
}
|
|
15
|
+
if (body === undefined || body === null) {
|
|
16
|
+
return 'application/octet-stream';
|
|
17
|
+
}
|
|
18
|
+
return 'application/json';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates Koa middleware that caches `GET` responses with a `2xx` status code.
|
|
22
|
+
*
|
|
23
|
+
* Requires `koa` to be installed as an optional peer dependency.
|
|
24
|
+
*
|
|
25
|
+
* @param cache - The {@link Memorize} instance to use as the backing store.
|
|
26
|
+
* @param options - Optional per-route options.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import Koa from 'koa';
|
|
31
|
+
* import Router from '@koa/router';
|
|
32
|
+
* import { memorize } from 'express-memorize';
|
|
33
|
+
* import { createKoaMiddleware } from 'express-memorize/koa';
|
|
34
|
+
*
|
|
35
|
+
* const app = new Koa();
|
|
36
|
+
* const router = new Router();
|
|
37
|
+
* const cache = memorize({ ttl: 30_000 });
|
|
38
|
+
*
|
|
39
|
+
* router.get('/users', createKoaMiddleware(cache), async (ctx) => {
|
|
40
|
+
* ctx.body = await usersService.findAll();
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
function createKoaMiddleware(cache, options) {
|
|
45
|
+
return async function memorizeKoaMiddleware(ctx, next) {
|
|
46
|
+
var _a;
|
|
47
|
+
if (ctx.method !== 'GET') {
|
|
48
|
+
await next();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (options === null || options === void 0 ? void 0 : options.noCache) {
|
|
52
|
+
ctx.set('X-Cache', 'BYPASS');
|
|
53
|
+
await next();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const key = (options === null || options === void 0 ? void 0 : options.key) ? options.key(ctx) : defaultKey(ctx);
|
|
57
|
+
const cached = cache._store.getRaw(key);
|
|
58
|
+
if (cached) {
|
|
59
|
+
ctx.set('X-Cache', 'HIT');
|
|
60
|
+
ctx.status = cached.statusCode;
|
|
61
|
+
ctx.type = cached.contentType;
|
|
62
|
+
ctx.body = cached.body;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
await next();
|
|
66
|
+
if (ctx.status >= 200 && ctx.status < 300) {
|
|
67
|
+
const contentType = ctx.response.type || inferContentType(ctx.body);
|
|
68
|
+
cache._store.set(key, { body: ctx.body, statusCode: ctx.status, contentType }, (_a = options === null || options === void 0 ? void 0 : options.ttl) !== null && _a !== void 0 ? _a : cache._ttl);
|
|
69
|
+
ctx.set('X-Cache', 'MISS');
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=koa.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"koa.js","sourceRoot":"","sources":["../../src/adapters/koa.ts"],"names":[],"mappings":";;AAwDA,kDAuCC;AAnFD,SAAS,UAAU,CAAC,GAAY;;IAC9B,OAAO,MAAA,GAAG,CAAC,WAAW,mCAAI,GAAG,CAAC,GAAG,CAAC;AACpC,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAa;IACrC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,YAAY,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QACrF,OAAO,0BAA0B,CAAC;IACpC,CAAC;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACxC,OAAO,0BAA0B,CAAC;IACpC,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,mBAAmB,CACjC,KAAe,EACf,OAA2B;IAE3B,OAAO,KAAK,UAAU,qBAAqB,CAAC,GAAY,EAAE,IAAI;;QAC5D,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;YAC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G,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -239,5 +239,11 @@ export interface Memorize {
|
|
|
239
239
|
* @internal
|
|
240
240
|
*/
|
|
241
241
|
_store: MemorizeStore;
|
|
242
|
+
/**
|
|
243
|
+
* Global TTL configured through `memorize({ ttl })`. Intended for use by
|
|
244
|
+
* framework adapters only.
|
|
245
|
+
* @internal
|
|
246
|
+
*/
|
|
247
|
+
_ttl?: number;
|
|
242
248
|
}
|
|
243
249
|
//# sourceMappingURL=Memorize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Memorize.d.ts","sourceRoot":"","sources":["../../src/domain/Memorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,cAAc,CAAC;IAEhD;;;;;;;;;;;;;;;;;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memorize.d.ts","sourceRoot":"","sources":["../src/memorize.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAGnE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,mBAAmB,EAAE,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,QAAQ,CAAC,OAAO,GAAE,eAAoB,GAAG,QAAQ,CA8ChE"}
|
package/dist/memorize.js
CHANGED
package/dist/memorize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memorize.js","sourceRoot":"","sources":["../src/memorize.ts"],"names":[],"mappings":";;AA0DA,
|
|
1
|
+
{"version":3,"file":"memorize.js","sourceRoot":"","sources":["../src/memorize.ts"],"names":[],"mappings":";;AA0DA,4BA8CC;AAxGD,mDAAgD;AAIhD,gDAA6D;AAI7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,SAAgB,QAAQ,CAAC,UAA2B,EAAE;IACpD,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IACpC,MAAM,KAAK,GAAG,IAAI,6BAAa,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,iBAAiB,GAAG,IAAA,iCAAuB,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAE9D,MAAM,KAAK,GAAG,UAAU,WAAiC;QACvD,OAAO,iBAAiB,CAAC,WAAW,CAAC,CAAC;IACxC,CAAa,CAAC;IAEd,KAAK,CAAC,OAAO,GAAG,CAAC,WAAiC,EAAE,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAEtF,KAAK,CAAC,GAAG,GAAG,CAAI,GAA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C,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1D,KAAK,CAAC,cAAc,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAC1E,KAAK,CAAC,KAAK,GAAY,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAC3C,KAAK,CAAC,EAAE,GAAe,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAmB,CAAC;IAC9D,KAAK,CAAC,IAAI,GAAa,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1C,KAAK,CAAC,QAAQ,GAAS,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC9C,KAAK,CAAC,QAAQ,GAAS,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC9C,KAAK,CAAC,MAAM,GAAW,KAAK,CAAC;IAC7B,KAAK,CAAC,IAAI,GAAa,GAAG,CAAC;IAE3B,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-memorize",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "In-memory cache middleware for Express.js. Caches GET responses with optional TTL — zero dependencies, fully typed.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,6 +18,14 @@
|
|
|
18
18
|
"types": "./dist/adapters/hono.d.ts",
|
|
19
19
|
"default": "./dist/adapters/hono.js"
|
|
20
20
|
},
|
|
21
|
+
"./fastify": {
|
|
22
|
+
"types": "./dist/adapters/fastify.d.ts",
|
|
23
|
+
"default": "./dist/adapters/fastify.js"
|
|
24
|
+
},
|
|
25
|
+
"./koa": {
|
|
26
|
+
"types": "./dist/adapters/koa.d.ts",
|
|
27
|
+
"default": "./dist/adapters/koa.js"
|
|
28
|
+
},
|
|
21
29
|
"./nestjs": {
|
|
22
30
|
"types": "./dist/adapters/nestjs.d.ts",
|
|
23
31
|
"default": "./dist/adapters/nestjs.js"
|
|
@@ -60,33 +68,49 @@
|
|
|
60
68
|
],
|
|
61
69
|
"license": "MIT",
|
|
62
70
|
"peerDependencies": {
|
|
71
|
+
"@koa/router": ">=10.0.0",
|
|
63
72
|
"@nestjs/common": ">=9.0.0",
|
|
64
73
|
"@nestjs/core": ">=9.0.0",
|
|
65
74
|
"express": ">=4.0.0",
|
|
75
|
+
"fastify": ">=4.0.0",
|
|
66
76
|
"hono": ">=4.0.0",
|
|
77
|
+
"koa": ">=2.0.0",
|
|
67
78
|
"rxjs": ">=7.0.0"
|
|
68
79
|
},
|
|
69
80
|
"peerDependenciesMeta": {
|
|
81
|
+
"@koa/router": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
70
84
|
"@nestjs/common": {
|
|
71
85
|
"optional": true
|
|
72
86
|
},
|
|
73
87
|
"@nestjs/core": {
|
|
74
88
|
"optional": true
|
|
75
89
|
},
|
|
90
|
+
"fastify": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
76
93
|
"hono": {
|
|
77
94
|
"optional": true
|
|
78
95
|
},
|
|
96
|
+
"koa": {
|
|
97
|
+
"optional": true
|
|
98
|
+
},
|
|
79
99
|
"rxjs": {
|
|
80
100
|
"optional": true
|
|
81
101
|
}
|
|
82
102
|
},
|
|
83
103
|
"devDependencies": {
|
|
104
|
+
"@koa/router": "^15.5.0",
|
|
84
105
|
"@semantic-release/changelog": "^6.0.3",
|
|
85
106
|
"@types/express": "^4.17.21",
|
|
86
107
|
"@types/jest": "^29.0.0",
|
|
108
|
+
"@types/koa": "^3.0.2",
|
|
87
109
|
"@types/node": "^20.0.0",
|
|
110
|
+
"fastify": "^5.6.2",
|
|
88
111
|
"hono": "^4.12.16",
|
|
89
112
|
"jest": "^29.0.0",
|
|
113
|
+
"koa": "^3.2.0",
|
|
90
114
|
"semantic-release": "^24.2.9",
|
|
91
115
|
"ts-jest": "^29.0.0",
|
|
92
116
|
"typedoc": "^0.28.18",
|