cache-manager 6.4.1 → 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 CHANGED
@@ -24,6 +24,75 @@ 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)
25
25
  * [v4 Documentation](https://github.com/jaredwray/cacheable/blob/main/packages/cache-manager/READMEv4.md)
26
26
 
27
+ # Migration from v5 to v6
28
+
29
+ `v6` is a major update and has breaking changes primarily around the storage adapters. We have moved to using [Keyv](https://keyv.org/) which are more actively maintained and have a larger community. Below are the changes you need to make to migrate from `v5` to `v6`. In `v5` the `memoryStore` was used to create a memory store, in `v6` you can use any storage adapter that Keyv supports. Below is an example of how to migrate from `v5` to `v6`:
30
+
31
+ ```ts
32
+ import { createCache, memoryStore } from 'cache-manager';
33
+
34
+ // Create memory cache synchronously
35
+ const memoryCache = createCache(memoryStore({
36
+ max: 100,
37
+ ttl: 10 * 1000 /*milliseconds*/,
38
+ }));
39
+ ```
40
+
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
+
43
+ ```ts
44
+ import { createCache } from 'cache-manager';
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');
58
+
59
+ const cache = createCache({
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],
76
+ });
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
79
+
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`:
81
+
82
+ ```ts
83
+ import { createCache } from 'cache-manager';
84
+ import { createKeyv } from 'cacheable';
85
+
86
+ const cache = createCache({
87
+ stores: [createKeyv({ ttl: 60000, lruSize: 5000 })],
88
+ });
89
+ ```
90
+
91
+ To learn more about `CacheableMemory` please visit: http://cacheable.org/docs/cacheable/#cacheablememory---in-memory-cache
92
+
93
+ If you are still wanting to use the legacy storage adapters you can use the `KeyvAdapter` to wrap the storage adapter. Below is an example of how to migrate from `v5` to `v6` using `cache-manager-redis-yet` by going to [Using Legacy Storage Adapters](#using-legacy-storage-adapters).
94
+
95
+
27
96
  ## Table of Contents
28
97
  * [Installation](#installation)
29
98
  * [Quick start](#quick-start)
@@ -492,9 +561,8 @@ import { Keyv } from 'keyv';
492
561
  import { redisStore } from 'cache-manager-redis-yet';
493
562
 
494
563
  const adapter = new KeyvAdapter( await redisStore() );
495
- const cache = createCache({
496
- stores: [new Keyv({ store: adapter })],
497
- });
564
+ const keyv = new Keyv({ store: adapter });
565
+ const cache = createCache({ stores: [keyv]});
498
566
  ```
499
567
 
500
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 stores = options?.stores?.length ? options.stores : [new import_keyv.Keyv()];
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 stores = options?.stores?.length ? options.stores : [new Keyv()];
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.1",
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.1"
53
+ "keyv": "^5.3.3"
54
54
  },
55
55
  "devDependencies": {
56
- "@faker-js/faker": "^9.5.1",
57
- "@keyv/redis": "^4.3.1",
58
- "@types/node": "^22.13.9",
59
- "@vitest/coverage-v8": "^3.0.7",
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.2",
64
- "vitest": "^3.0.7",
64
+ "typescript": "^5.8.3",
65
+ "vitest": "^3.1.3",
65
66
  "xo": "^0.60.0",
66
- "cacheable": "^1.8.9"
67
+ "cacheable": "^1.9.0"
67
68
  },
68
69
  "xo": {
69
70
  "rules": {