cache-manager 6.1.3 → 6.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/README.md +14 -2
- package/dist/index.cjs +17 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +17 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[<img align="center" src="https://cacheable.org/symbol.svg" alt="Cacheable" />](https://github.com/jaredwray/cacheable)
|
|
2
2
|
|
|
3
|
-
# cache-manager
|
|
3
|
+
# cache-manager
|
|
4
4
|
[](https://codecov.io/gh/jaredwray/cacheable)
|
|
5
5
|
[](https://github.com/jaredwray/cacheable/actions/workflows/tests.yml)
|
|
6
6
|
[](https://npmjs.com/package/cache-manager)
|
|
@@ -18,7 +18,7 @@ A cache module for NodeJS that allows easy wrapping of functions in cache, tiere
|
|
|
18
18
|
|
|
19
19
|
We moved to using [Keyv](https://keyv.org/) which are more actively maintained and have a larger community.
|
|
20
20
|
|
|
21
|
-
A special thanks to [Tim Phan](https://github.com/timphandev) who
|
|
21
|
+
A special thanks to [Tim Phan](https://github.com/timphandev) who took `cache-manager` v5 and ported it to [Keyv](https://keyv.org/) which is the foundation of v6. 🎉 Another special thanks to [Doug Ayers](https://github.com/douglascayers) who wrote `promise-coalesce` which was used in v5 and now embedded in v6.
|
|
22
22
|
|
|
23
23
|
If you are looking for older documentation you can find it here:
|
|
24
24
|
* [v5 Documentation](https://github.com/jaredwray/cacheable/blob/main/packages/cache-manager/READMEv5.md)
|
|
@@ -332,6 +332,18 @@ await cache.wrap('error', () => {
|
|
|
332
332
|
|
|
333
333
|
See unit tests in [`test/wrap.test.ts`](./test/wrap.test.ts) for more information.
|
|
334
334
|
|
|
335
|
+
## disconnect
|
|
336
|
+
|
|
337
|
+
`disconnect(key): Promise<void>`
|
|
338
|
+
|
|
339
|
+
Will disconnect from the relevant store(s). It is highly recomended to use this when using a [Keyv](https://keyv.org/) storage adapter that requires a disconnect. For each storage adapter, the use case for when to use disconnect is different. An example is that `@keyv/redis` should be used only when you are done with the cache.
|
|
340
|
+
|
|
341
|
+
```ts
|
|
342
|
+
await cache.disconnect();
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
See unit tests in [`test/disconnect.test.ts`](./test/disconnect.test.ts) for more information.
|
|
346
|
+
|
|
335
347
|
# Events
|
|
336
348
|
## set
|
|
337
349
|
Fired when a key has been added or changed.
|
package/dist/index.cjs
CHANGED
|
@@ -146,6 +146,9 @@ var KeyvAdapter = class {
|
|
|
146
146
|
this._cache.on?.(event, listener);
|
|
147
147
|
return this;
|
|
148
148
|
}
|
|
149
|
+
async disconnect() {
|
|
150
|
+
await this._cache.disconnect?.();
|
|
151
|
+
}
|
|
149
152
|
};
|
|
150
153
|
|
|
151
154
|
// src/index.ts
|
|
@@ -210,6 +213,11 @@ var createCache = (options) => {
|
|
|
210
213
|
for (const item of list) {
|
|
211
214
|
promises.push(stores2.map(async (store) => store.set(item.key, item.value, item.ttl)));
|
|
212
215
|
}
|
|
216
|
+
if (nonBlocking) {
|
|
217
|
+
Promise.all(promises);
|
|
218
|
+
eventEmitter.emit("mset", { list });
|
|
219
|
+
return list;
|
|
220
|
+
}
|
|
213
221
|
await Promise.all(promises);
|
|
214
222
|
eventEmitter.emit("mset", { list });
|
|
215
223
|
return list;
|
|
@@ -310,6 +318,13 @@ var createCache = (options) => {
|
|
|
310
318
|
});
|
|
311
319
|
const on = (event, listener) => eventEmitter.addListener(event, listener);
|
|
312
320
|
const off = (event, listener) => eventEmitter.removeListener(event, listener);
|
|
321
|
+
const disconnect = async () => {
|
|
322
|
+
try {
|
|
323
|
+
await Promise.all(stores.map(async (store) => store.disconnect()));
|
|
324
|
+
} catch (error) {
|
|
325
|
+
return Promise.reject(error);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
313
328
|
return {
|
|
314
329
|
get,
|
|
315
330
|
mget,
|
|
@@ -320,7 +335,8 @@ var createCache = (options) => {
|
|
|
320
335
|
clear,
|
|
321
336
|
wrap,
|
|
322
337
|
on,
|
|
323
|
-
off
|
|
338
|
+
off,
|
|
339
|
+
disconnect
|
|
324
340
|
};
|
|
325
341
|
};
|
|
326
342
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.d.cts
CHANGED
|
@@ -14,6 +14,7 @@ type CacheManagerStore = {
|
|
|
14
14
|
keys(): Promise<string[]>;
|
|
15
15
|
reset?(): Promise<void>;
|
|
16
16
|
on?(event: string, listener: (...arguments_: any[]) => void): void;
|
|
17
|
+
disconnect?(): Promise<void>;
|
|
17
18
|
};
|
|
18
19
|
declare class KeyvAdapter implements KeyvStoreAdapter {
|
|
19
20
|
opts: any;
|
|
@@ -28,6 +29,7 @@ declare class KeyvAdapter implements KeyvStoreAdapter {
|
|
|
28
29
|
getMany?<T>(keys: string[]): Promise<Array<StoredData<T | undefined>>>;
|
|
29
30
|
deleteMany?(key: string[]): Promise<boolean>;
|
|
30
31
|
on(event: string, listener: (...arguments_: any[]) => void): this;
|
|
32
|
+
disconnect?(): Promise<void>;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
type CreateCacheOptions = {
|
|
@@ -72,6 +74,7 @@ declare const createCache: (options?: CreateCacheOptions) => {
|
|
|
72
74
|
wrap: <T>(key: string, fnc: () => T | Promise<T>, ttl?: number | ((value: T) => number), refreshThreshold?: number) => Promise<T>;
|
|
73
75
|
on: <E extends keyof Events>(event: E, listener: Events[E]) => EventEmitter<[never]>;
|
|
74
76
|
off: <E extends keyof Events>(event: E, listener: Events[E]) => EventEmitter<[never]>;
|
|
77
|
+
disconnect: () => Promise<undefined>;
|
|
75
78
|
};
|
|
76
79
|
|
|
77
80
|
export { type CacheManagerStore, type CreateCacheOptions, type Events, KeyvAdapter, createCache };
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ type CacheManagerStore = {
|
|
|
14
14
|
keys(): Promise<string[]>;
|
|
15
15
|
reset?(): Promise<void>;
|
|
16
16
|
on?(event: string, listener: (...arguments_: any[]) => void): void;
|
|
17
|
+
disconnect?(): Promise<void>;
|
|
17
18
|
};
|
|
18
19
|
declare class KeyvAdapter implements KeyvStoreAdapter {
|
|
19
20
|
opts: any;
|
|
@@ -28,6 +29,7 @@ declare class KeyvAdapter implements KeyvStoreAdapter {
|
|
|
28
29
|
getMany?<T>(keys: string[]): Promise<Array<StoredData<T | undefined>>>;
|
|
29
30
|
deleteMany?(key: string[]): Promise<boolean>;
|
|
30
31
|
on(event: string, listener: (...arguments_: any[]) => void): this;
|
|
32
|
+
disconnect?(): Promise<void>;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
type CreateCacheOptions = {
|
|
@@ -72,6 +74,7 @@ declare const createCache: (options?: CreateCacheOptions) => {
|
|
|
72
74
|
wrap: <T>(key: string, fnc: () => T | Promise<T>, ttl?: number | ((value: T) => number), refreshThreshold?: number) => Promise<T>;
|
|
73
75
|
on: <E extends keyof Events>(event: E, listener: Events[E]) => EventEmitter<[never]>;
|
|
74
76
|
off: <E extends keyof Events>(event: E, listener: Events[E]) => EventEmitter<[never]>;
|
|
77
|
+
disconnect: () => Promise<undefined>;
|
|
75
78
|
};
|
|
76
79
|
|
|
77
80
|
export { type CacheManagerStore, type CreateCacheOptions, type Events, KeyvAdapter, createCache };
|
package/dist/index.js
CHANGED
|
@@ -111,6 +111,9 @@ var KeyvAdapter = class {
|
|
|
111
111
|
this._cache.on?.(event, listener);
|
|
112
112
|
return this;
|
|
113
113
|
}
|
|
114
|
+
async disconnect() {
|
|
115
|
+
await this._cache.disconnect?.();
|
|
116
|
+
}
|
|
114
117
|
};
|
|
115
118
|
|
|
116
119
|
// src/index.ts
|
|
@@ -175,6 +178,11 @@ var createCache = (options) => {
|
|
|
175
178
|
for (const item of list) {
|
|
176
179
|
promises.push(stores2.map(async (store) => store.set(item.key, item.value, item.ttl)));
|
|
177
180
|
}
|
|
181
|
+
if (nonBlocking) {
|
|
182
|
+
Promise.all(promises);
|
|
183
|
+
eventEmitter.emit("mset", { list });
|
|
184
|
+
return list;
|
|
185
|
+
}
|
|
178
186
|
await Promise.all(promises);
|
|
179
187
|
eventEmitter.emit("mset", { list });
|
|
180
188
|
return list;
|
|
@@ -275,6 +283,13 @@ var createCache = (options) => {
|
|
|
275
283
|
});
|
|
276
284
|
const on = (event, listener) => eventEmitter.addListener(event, listener);
|
|
277
285
|
const off = (event, listener) => eventEmitter.removeListener(event, listener);
|
|
286
|
+
const disconnect = async () => {
|
|
287
|
+
try {
|
|
288
|
+
await Promise.all(stores.map(async (store) => store.disconnect()));
|
|
289
|
+
} catch (error) {
|
|
290
|
+
return Promise.reject(error);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
278
293
|
return {
|
|
279
294
|
get,
|
|
280
295
|
mget,
|
|
@@ -285,7 +300,8 @@ var createCache = (options) => {
|
|
|
285
300
|
clear,
|
|
286
301
|
wrap,
|
|
287
302
|
on,
|
|
288
|
-
off
|
|
303
|
+
off,
|
|
304
|
+
disconnect
|
|
289
305
|
};
|
|
290
306
|
};
|
|
291
307
|
export {
|