cache-manager 7.0.1 → 7.1.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/dist/index.cjs +31 -10
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +31 -10
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -194,11 +194,35 @@ var createCache = (options) => {
|
|
|
194
194
|
return result;
|
|
195
195
|
};
|
|
196
196
|
const mget = async (keys) => {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
197
|
+
let result = keys.map(() => void 0);
|
|
198
|
+
if (nonBlocking) {
|
|
199
|
+
try {
|
|
200
|
+
result = await Promise.race(stores.map(async (store) => store.getMany(keys)));
|
|
201
|
+
} catch (error) {
|
|
202
|
+
eventEmitter.emit("mget", { keys, error });
|
|
203
|
+
}
|
|
204
|
+
} else {
|
|
205
|
+
for (const store of stores) {
|
|
206
|
+
try {
|
|
207
|
+
const missingValues = result.map((value, index) => value === void 0 ? { originalIndex: index, key: keys[index] } : void 0).filter((v) => v !== void 0);
|
|
208
|
+
if (missingValues.length === 0) {
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
const missingKeys = missingValues.map((v) => v.key);
|
|
212
|
+
const cacheValue = await store.getMany(missingKeys);
|
|
213
|
+
for (const [index, value] of cacheValue.entries()) {
|
|
214
|
+
if (value === void 0) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const { originalIndex } = missingValues[index];
|
|
218
|
+
result[originalIndex] = value;
|
|
219
|
+
}
|
|
220
|
+
} catch (error) {
|
|
221
|
+
eventEmitter.emit("mget", { keys, error });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
201
224
|
}
|
|
225
|
+
eventEmitter.emit("mget", { keys, values: result });
|
|
202
226
|
return result;
|
|
203
227
|
};
|
|
204
228
|
const ttl = async (key) => {
|
|
@@ -246,13 +270,10 @@ var createCache = (options) => {
|
|
|
246
270
|
return Promise.reject(error);
|
|
247
271
|
}
|
|
248
272
|
};
|
|
249
|
-
const mset = async (stores2,
|
|
250
|
-
const
|
|
273
|
+
const mset = async (stores2, rawList) => {
|
|
274
|
+
const list = rawList.map(({ key, value, ttl: ttl2 }) => ({ key, value, ttl: ttl2 ?? options?.ttl }));
|
|
251
275
|
try {
|
|
252
|
-
const promises =
|
|
253
|
-
for (const item of list) {
|
|
254
|
-
promises.push(...stores2.map(async (store) => store.set(item.key, item.value, item.ttl)));
|
|
255
|
-
}
|
|
276
|
+
const promises = stores2.map(async (store) => store.setMany(list));
|
|
256
277
|
if (nonBlocking) {
|
|
257
278
|
Promise.all(promises);
|
|
258
279
|
eventEmitter.emit("mset", { list });
|
package/dist/index.d.cts
CHANGED
|
@@ -79,11 +79,24 @@ type Events = {
|
|
|
79
79
|
value?: T;
|
|
80
80
|
error?: unknown;
|
|
81
81
|
}) => void;
|
|
82
|
+
mget: <T>(data: {
|
|
83
|
+
keys: string[];
|
|
84
|
+
value?: T[];
|
|
85
|
+
error?: unknown;
|
|
86
|
+
}) => void;
|
|
82
87
|
set: <T>(data: {
|
|
83
88
|
key: string;
|
|
84
89
|
value: T;
|
|
85
90
|
error?: unknown;
|
|
86
91
|
}) => void;
|
|
92
|
+
mset: <T>(data: {
|
|
93
|
+
list: Array<{
|
|
94
|
+
key: string;
|
|
95
|
+
value: T;
|
|
96
|
+
ttl?: number;
|
|
97
|
+
}>;
|
|
98
|
+
error?: unknown;
|
|
99
|
+
}) => void;
|
|
87
100
|
del: (data: {
|
|
88
101
|
key: string;
|
|
89
102
|
error?: unknown;
|
package/dist/index.d.ts
CHANGED
|
@@ -79,11 +79,24 @@ type Events = {
|
|
|
79
79
|
value?: T;
|
|
80
80
|
error?: unknown;
|
|
81
81
|
}) => void;
|
|
82
|
+
mget: <T>(data: {
|
|
83
|
+
keys: string[];
|
|
84
|
+
value?: T[];
|
|
85
|
+
error?: unknown;
|
|
86
|
+
}) => void;
|
|
82
87
|
set: <T>(data: {
|
|
83
88
|
key: string;
|
|
84
89
|
value: T;
|
|
85
90
|
error?: unknown;
|
|
86
91
|
}) => void;
|
|
92
|
+
mset: <T>(data: {
|
|
93
|
+
list: Array<{
|
|
94
|
+
key: string;
|
|
95
|
+
value: T;
|
|
96
|
+
ttl?: number;
|
|
97
|
+
}>;
|
|
98
|
+
error?: unknown;
|
|
99
|
+
}) => void;
|
|
87
100
|
del: (data: {
|
|
88
101
|
key: string;
|
|
89
102
|
error?: unknown;
|
package/dist/index.js
CHANGED
|
@@ -159,11 +159,35 @@ var createCache = (options) => {
|
|
|
159
159
|
return result;
|
|
160
160
|
};
|
|
161
161
|
const mget = async (keys) => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
let result = keys.map(() => void 0);
|
|
163
|
+
if (nonBlocking) {
|
|
164
|
+
try {
|
|
165
|
+
result = await Promise.race(stores.map(async (store) => store.getMany(keys)));
|
|
166
|
+
} catch (error) {
|
|
167
|
+
eventEmitter.emit("mget", { keys, error });
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
for (const store of stores) {
|
|
171
|
+
try {
|
|
172
|
+
const missingValues = result.map((value, index) => value === void 0 ? { originalIndex: index, key: keys[index] } : void 0).filter((v) => v !== void 0);
|
|
173
|
+
if (missingValues.length === 0) {
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
const missingKeys = missingValues.map((v) => v.key);
|
|
177
|
+
const cacheValue = await store.getMany(missingKeys);
|
|
178
|
+
for (const [index, value] of cacheValue.entries()) {
|
|
179
|
+
if (value === void 0) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const { originalIndex } = missingValues[index];
|
|
183
|
+
result[originalIndex] = value;
|
|
184
|
+
}
|
|
185
|
+
} catch (error) {
|
|
186
|
+
eventEmitter.emit("mget", { keys, error });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
166
189
|
}
|
|
190
|
+
eventEmitter.emit("mget", { keys, values: result });
|
|
167
191
|
return result;
|
|
168
192
|
};
|
|
169
193
|
const ttl = async (key) => {
|
|
@@ -211,13 +235,10 @@ var createCache = (options) => {
|
|
|
211
235
|
return Promise.reject(error);
|
|
212
236
|
}
|
|
213
237
|
};
|
|
214
|
-
const mset = async (stores2,
|
|
215
|
-
const
|
|
238
|
+
const mset = async (stores2, rawList) => {
|
|
239
|
+
const list = rawList.map(({ key, value, ttl: ttl2 }) => ({ key, value, ttl: ttl2 ?? options?.ttl }));
|
|
216
240
|
try {
|
|
217
|
-
const promises =
|
|
218
|
-
for (const item of list) {
|
|
219
|
-
promises.push(...stores2.map(async (store) => store.set(item.key, item.value, item.ttl)));
|
|
220
|
-
}
|
|
241
|
+
const promises = stores2.map(async (store) => store.setMany(list));
|
|
221
242
|
if (nonBlocking) {
|
|
222
243
|
Promise.all(promises);
|
|
223
244
|
eventEmitter.emit("mset", { list });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cache-manager",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Cache Manager for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"keyv": "^5.3.4"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@faker-js/faker": "^9.
|
|
57
|
-
"@keyv/redis": "^4.
|
|
58
|
-
"@types/node": "^24.0.
|
|
56
|
+
"@faker-js/faker": "^9.9.0",
|
|
57
|
+
"@keyv/redis": "^4.6.0",
|
|
58
|
+
"@types/node": "^24.0.14",
|
|
59
59
|
"@vitest/coverage-v8": "^3.2.4",
|
|
60
60
|
"@vitest/spy": "^3.2.4",
|
|
61
61
|
"cache-manager-redis-yet": "^5.1.5",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"tsup": "^8.5.0",
|
|
64
64
|
"typescript": "^5.8.3",
|
|
65
65
|
"vitest": "^3.2.4",
|
|
66
|
-
"xo": "^1.
|
|
67
|
-
"cacheable": "^1.10.
|
|
66
|
+
"xo": "^1.2.0",
|
|
67
|
+
"cacheable": "^1.10.3"
|
|
68
68
|
},
|
|
69
69
|
"xo": {
|
|
70
70
|
"rules": {
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"scripts": {
|
|
76
76
|
"clean": "rimraf ./dist ./coverage ./node_modules",
|
|
77
77
|
"test": "xo --fix && vitest run --coverage",
|
|
78
|
-
"test:ci": "xo && vitest run",
|
|
78
|
+
"test:ci": "xo && vitest run --coverage",
|
|
79
79
|
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
|
|
80
80
|
"prepublish": "pnpm run build"
|
|
81
81
|
}
|