cache-manager 6.4.2 → 6.4.3
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 +35 -8
- package/dist/index.cjs +6 -3
- package/dist/index.js +6 -3
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -38,25 +38,53 @@ const memoryCache = createCache(memoryStore({
|
|
|
38
38
|
}));
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
In `v6` you can use any storage adapter that Keyv supports. Below is an example of
|
|
41
|
+
In `v6` you can use any storage adapter that Keyv supports. Below is an example of using the in memory store with `Keyv`:
|
|
42
42
|
|
|
43
43
|
```ts
|
|
44
44
|
import { createCache } from 'cache-manager';
|
|
45
|
-
|
|
45
|
+
|
|
46
|
+
const cache = createCache();
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
If you would like to do multiple stores you can do the following:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { createCache } from 'cache-manager';
|
|
53
|
+
import { createKeyv } from 'cacheable';
|
|
54
|
+
import { createKeyv as createKeyvRedis } from '@keyv/redis';
|
|
55
|
+
|
|
56
|
+
const memoryStore = createKeyv();
|
|
57
|
+
const redisStore = createKeyvRedis('redis://user:pass@localhost:6379');
|
|
46
58
|
|
|
47
59
|
const cache = createCache({
|
|
48
|
-
stores: [
|
|
60
|
+
stores: [memoryStore, redisStore],
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
When doing in memory caching and getting errors on `symbol` or if the object is coming back wrong like on `Uint8Array` you will want to set the `serialization` and `deserialization` options in Keyv to `undefined` as it will try to do json serialization.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { createCache } from "cache-manager";
|
|
68
|
+
import { Keyv } from "keyv";
|
|
69
|
+
|
|
70
|
+
const keyv = new Keyv();
|
|
71
|
+
keyv.serialize = undefined;
|
|
72
|
+
keyv.deserialize = undefined;
|
|
73
|
+
|
|
74
|
+
const memoryCache = createCache({
|
|
75
|
+
stores: [keyv],
|
|
49
76
|
});
|
|
50
77
|
```
|
|
78
|
+
The other option is to set the serialization to something that is not `JSON.stringify`. You can read more about it here: https://keyv.org/docs/keyv/#custom-serializers
|
|
51
79
|
|
|
52
80
|
If you would like a more robust in memory storage adapter you can use `CacheableMemory` from Cacheable. Below is an example of how to migrate from `v5` to `v6` using `CacheableMemory`:
|
|
53
81
|
|
|
54
82
|
```ts
|
|
55
83
|
import { createCache } from 'cache-manager';
|
|
56
|
-
import {
|
|
84
|
+
import { createKeyv } from 'cacheable';
|
|
57
85
|
|
|
58
86
|
const cache = createCache({
|
|
59
|
-
stores: [
|
|
87
|
+
stores: [createKeyv({ ttl: 60000, lruSize: 5000 })],
|
|
60
88
|
});
|
|
61
89
|
```
|
|
62
90
|
|
|
@@ -533,9 +561,8 @@ import { Keyv } from 'keyv';
|
|
|
533
561
|
import { redisStore } from 'cache-manager-redis-yet';
|
|
534
562
|
|
|
535
563
|
const adapter = new KeyvAdapter( await redisStore() );
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
});
|
|
564
|
+
const keyv = new Keyv({ store: adapter });
|
|
565
|
+
const cache = createCache({ stores: [keyv]});
|
|
539
566
|
```
|
|
540
567
|
|
|
541
568
|
This adapter will allow you to add in any storage adapter. If there are issues it needs to follow `CacheManagerStore` interface.
|
package/dist/index.cjs
CHANGED
|
@@ -159,7 +159,10 @@ var KeyvAdapter = class {
|
|
|
159
159
|
// src/index.ts
|
|
160
160
|
var createCache = (options) => {
|
|
161
161
|
const eventEmitter = new import_node_events.default();
|
|
162
|
-
const
|
|
162
|
+
const keyv = new import_keyv.Keyv();
|
|
163
|
+
keyv.serialize = void 0;
|
|
164
|
+
keyv.deserialize = void 0;
|
|
165
|
+
const stores = options?.stores?.length ? options.stores : [keyv];
|
|
163
166
|
const nonBlocking = options?.nonBlocking ?? false;
|
|
164
167
|
const _cacheId = options?.cacheId ?? Math.random().toString(36).slice(2);
|
|
165
168
|
const get = async (key) => {
|
|
@@ -247,7 +250,7 @@ var createCache = (options) => {
|
|
|
247
250
|
try {
|
|
248
251
|
const promises = [];
|
|
249
252
|
for (const item of list) {
|
|
250
|
-
promises.push(stores2.map(async (store) => store.set(item.key, item.value, item.ttl)));
|
|
253
|
+
promises.push(...stores2.map(async (store) => store.set(item.key, item.value, item.ttl)));
|
|
251
254
|
}
|
|
252
255
|
if (nonBlocking) {
|
|
253
256
|
Promise.all(promises);
|
|
@@ -281,7 +284,7 @@ var createCache = (options) => {
|
|
|
281
284
|
try {
|
|
282
285
|
const promises = [];
|
|
283
286
|
for (const key of keys) {
|
|
284
|
-
promises.push(stores.map(async (store) => store.delete(key)));
|
|
287
|
+
promises.push(...stores.map(async (store) => store.delete(key)));
|
|
285
288
|
}
|
|
286
289
|
if (nonBlocking) {
|
|
287
290
|
Promise.all(promises);
|
package/dist/index.js
CHANGED
|
@@ -124,7 +124,10 @@ var KeyvAdapter = class {
|
|
|
124
124
|
// src/index.ts
|
|
125
125
|
var createCache = (options) => {
|
|
126
126
|
const eventEmitter = new EventEmitter();
|
|
127
|
-
const
|
|
127
|
+
const keyv = new Keyv();
|
|
128
|
+
keyv.serialize = void 0;
|
|
129
|
+
keyv.deserialize = void 0;
|
|
130
|
+
const stores = options?.stores?.length ? options.stores : [keyv];
|
|
128
131
|
const nonBlocking = options?.nonBlocking ?? false;
|
|
129
132
|
const _cacheId = options?.cacheId ?? Math.random().toString(36).slice(2);
|
|
130
133
|
const get = async (key) => {
|
|
@@ -212,7 +215,7 @@ var createCache = (options) => {
|
|
|
212
215
|
try {
|
|
213
216
|
const promises = [];
|
|
214
217
|
for (const item of list) {
|
|
215
|
-
promises.push(stores2.map(async (store) => store.set(item.key, item.value, item.ttl)));
|
|
218
|
+
promises.push(...stores2.map(async (store) => store.set(item.key, item.value, item.ttl)));
|
|
216
219
|
}
|
|
217
220
|
if (nonBlocking) {
|
|
218
221
|
Promise.all(promises);
|
|
@@ -246,7 +249,7 @@ var createCache = (options) => {
|
|
|
246
249
|
try {
|
|
247
250
|
const promises = [];
|
|
248
251
|
for (const key of keys) {
|
|
249
|
-
promises.push(stores.map(async (store) => store.delete(key)));
|
|
252
|
+
promises.push(...stores.map(async (store) => store.delete(key)));
|
|
250
253
|
}
|
|
251
254
|
if (nonBlocking) {
|
|
252
255
|
Promise.all(promises);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cache-manager",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.3",
|
|
4
4
|
"description": "Cache Manager for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -50,20 +50,21 @@
|
|
|
50
50
|
],
|
|
51
51
|
"license": "MIT",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"keyv": "^5.3.
|
|
53
|
+
"keyv": "^5.3.3"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@faker-js/faker": "^9.
|
|
57
|
-
"@keyv/redis": "^4.
|
|
58
|
-
"@types/node": "^22.
|
|
59
|
-
"@vitest/coverage-v8": "^3.1.
|
|
56
|
+
"@faker-js/faker": "^9.7.0",
|
|
57
|
+
"@keyv/redis": "^4.4.0",
|
|
58
|
+
"@types/node": "^22.15.3",
|
|
59
|
+
"@vitest/coverage-v8": "^3.1.3",
|
|
60
|
+
"@vitest/spy": "^3.1.3",
|
|
60
61
|
"cache-manager-redis-yet": "^5.1.5",
|
|
61
62
|
"rimraf": "^6.0.1",
|
|
62
63
|
"tsup": "^8.4.0",
|
|
63
|
-
"typescript": "^5.8.
|
|
64
|
-
"vitest": "^3.1.
|
|
64
|
+
"typescript": "^5.8.3",
|
|
65
|
+
"vitest": "^3.1.3",
|
|
65
66
|
"xo": "^0.60.0",
|
|
66
|
-
"cacheable": "^1.
|
|
67
|
+
"cacheable": "^1.9.0"
|
|
67
68
|
},
|
|
68
69
|
"xo": {
|
|
69
70
|
"rules": {
|