cache-manager 6.4.3 → 7.0.1

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
@@ -20,9 +20,18 @@ We moved to using [Keyv](https://keyv.org/) which are more actively maintained a
20
20
 
21
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
- If you are looking for older documentation you can find it here:
24
- * [v5 Documentation](https://github.com/jaredwray/cacheable/blob/main/packages/cache-manager/READMEv5.md)
25
- * [v4 Documentation](https://github.com/jaredwray/cacheable/blob/main/packages/cache-manager/READMEv4.md)
23
+ # Migration from v6 to v7
24
+
25
+ `v7` has only one breaking change which is changing the return type from `null` to `undefined` when there is no data to return. This is to align with the [Keyv](https://keyv.org) API and to make it more consistent with the rest of the methods. Below is an example of how to migrate from `v6` to `v7`:
26
+
27
+ ```ts
28
+ import { createCache } from 'cache-manager';
29
+
30
+ const cache = createCache();
31
+ const result = await cache.get('key');
32
+ // result will be undefined if the key is not found or expired
33
+ console.log(result); // undefined
34
+ ```
26
35
 
27
36
  # Migration from v5 to v6
28
37
 
@@ -92,6 +101,10 @@ To learn more about `CacheableMemory` please visit: http://cacheable.org/docs/ca
92
101
 
93
102
  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
103
 
104
+ If you are looking for older documentation you can find it here:
105
+ * [v5 Documentation](https://github.com/jaredwray/cacheable/blob/main/packages/cache-manager/READMEv5.md)
106
+ * [v4 Documentation](https://github.com/jaredwray/cacheable/blob/main/packages/cache-manager/READMEv4.md)
107
+
95
108
 
96
109
  ## Table of Contents
97
110
  * [Installation](#installation)
@@ -324,7 +337,7 @@ await cache.mget(['key-1', 'key-2', 'key-3'])
324
337
  Gets the expiration time of a key in milliseconds. Returns a null if not found or expired.
325
338
 
326
339
  ```ts
327
- await cache.set('key', 'value', 1000); // expires after 5 seconds
340
+ await cache.set('key', 'value', 1000); // expires after 1 second
328
341
 
329
342
  await cache.ttl('key'); // => the expiration time in milliseconds
330
343
 
@@ -470,7 +483,7 @@ Returns the list of Keyv instances. This can be used to get the list of stores a
470
483
  const cache = createCache({cacheId: 'my-cache-id'});
471
484
  cache.cacheId(); // => 'my-cache-id'
472
485
  ```
473
- See unit tests in [`test/cache-id.test.ts`](./test/get.test.ts) for more information.
486
+ See unit tests in [`test/cache-id.test.ts`](./test/cache-id.test.ts) for more information.
474
487
 
475
488
  # Events
476
489
  ## set
package/dist/index.cjs CHANGED
@@ -123,7 +123,8 @@ var KeyvAdapter = class {
123
123
  return void 0;
124
124
  }
125
125
  async set(key, value, ttl) {
126
- return this._cache.set(key, value, ttl).then(() => true);
126
+ await this._cache.set(key, value, ttl);
127
+ return true;
127
128
  }
128
129
  async delete(key) {
129
130
  await this._cache.del(key);
@@ -166,12 +167,12 @@ var createCache = (options) => {
166
167
  const nonBlocking = options?.nonBlocking ?? false;
167
168
  const _cacheId = options?.cacheId ?? Math.random().toString(36).slice(2);
168
169
  const get = async (key) => {
169
- let result = null;
170
+ let result;
170
171
  if (nonBlocking) {
171
172
  try {
172
173
  result = await Promise.race(stores.map(async (store) => store.get(key)));
173
174
  if (result === void 0) {
174
- return null;
175
+ return void 0;
175
176
  }
176
177
  } catch (error) {
177
178
  eventEmitter.emit("get", { key, error });
@@ -201,12 +202,12 @@ var createCache = (options) => {
201
202
  return result;
202
203
  };
203
204
  const ttl = async (key) => {
204
- let result = null;
205
+ let result;
205
206
  if (nonBlocking) {
206
207
  try {
207
208
  result = await Promise.race(stores.map(async (store) => store.get(key, { raw: true })));
208
209
  if (result === void 0) {
209
- return null;
210
+ return void 0;
210
211
  }
211
212
  } catch (error) {
212
213
  eventEmitter.emit("ttl", { key, error });
@@ -228,7 +229,7 @@ var createCache = (options) => {
228
229
  if (result?.expires) {
229
230
  return result.expires;
230
231
  }
231
- return null;
232
+ return void 0;
232
233
  };
233
234
  const set = async (stores2, key, value, ttl2) => {
234
235
  try {
package/dist/index.d.cts CHANGED
@@ -48,9 +48,9 @@ type WrapOptionsRaw<T> = WrapOptions<T> & {
48
48
  raw: true;
49
49
  };
50
50
  type Cache = {
51
- get: <T>(key: string) => Promise<T | null>;
52
- mget: <T>(keys: string[]) => Promise<Array<T | null>>;
53
- ttl: (key: string) => Promise<number | null>;
51
+ get: <T>(key: string) => Promise<T | undefined>;
52
+ mget: <T>(keys: string[]) => Promise<Array<T | undefined>>;
53
+ ttl: (key: string) => Promise<number | undefined>;
54
54
  set: <T>(key: string, value: T, ttl?: number) => Promise<T>;
55
55
  mset: <T>(list: Array<{
56
56
  key: string;
@@ -74,6 +74,11 @@ type Cache = {
74
74
  wrap<T>(key: string, fnc: () => T | Promise<T>, options: WrapOptionsRaw<T>): Promise<StoredDataRaw<T>>;
75
75
  };
76
76
  type Events = {
77
+ get: <T>(data: {
78
+ key: string;
79
+ value?: T;
80
+ error?: unknown;
81
+ }) => void;
77
82
  set: <T>(data: {
78
83
  key: string;
79
84
  value: T;
package/dist/index.d.ts CHANGED
@@ -48,9 +48,9 @@ type WrapOptionsRaw<T> = WrapOptions<T> & {
48
48
  raw: true;
49
49
  };
50
50
  type Cache = {
51
- get: <T>(key: string) => Promise<T | null>;
52
- mget: <T>(keys: string[]) => Promise<Array<T | null>>;
53
- ttl: (key: string) => Promise<number | null>;
51
+ get: <T>(key: string) => Promise<T | undefined>;
52
+ mget: <T>(keys: string[]) => Promise<Array<T | undefined>>;
53
+ ttl: (key: string) => Promise<number | undefined>;
54
54
  set: <T>(key: string, value: T, ttl?: number) => Promise<T>;
55
55
  mset: <T>(list: Array<{
56
56
  key: string;
@@ -74,6 +74,11 @@ type Cache = {
74
74
  wrap<T>(key: string, fnc: () => T | Promise<T>, options: WrapOptionsRaw<T>): Promise<StoredDataRaw<T>>;
75
75
  };
76
76
  type Events = {
77
+ get: <T>(data: {
78
+ key: string;
79
+ value?: T;
80
+ error?: unknown;
81
+ }) => void;
77
82
  set: <T>(data: {
78
83
  key: string;
79
84
  value: T;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import EventEmitter from "node:events";
2
+ import EventEmitter from "events";
3
3
  import { Keyv } from "keyv";
4
4
 
5
5
  // src/coalesce-async.ts
@@ -88,7 +88,8 @@ var KeyvAdapter = class {
88
88
  return void 0;
89
89
  }
90
90
  async set(key, value, ttl) {
91
- return this._cache.set(key, value, ttl).then(() => true);
91
+ await this._cache.set(key, value, ttl);
92
+ return true;
92
93
  }
93
94
  async delete(key) {
94
95
  await this._cache.del(key);
@@ -131,12 +132,12 @@ var createCache = (options) => {
131
132
  const nonBlocking = options?.nonBlocking ?? false;
132
133
  const _cacheId = options?.cacheId ?? Math.random().toString(36).slice(2);
133
134
  const get = async (key) => {
134
- let result = null;
135
+ let result;
135
136
  if (nonBlocking) {
136
137
  try {
137
138
  result = await Promise.race(stores.map(async (store) => store.get(key)));
138
139
  if (result === void 0) {
139
- return null;
140
+ return void 0;
140
141
  }
141
142
  } catch (error) {
142
143
  eventEmitter.emit("get", { key, error });
@@ -166,12 +167,12 @@ var createCache = (options) => {
166
167
  return result;
167
168
  };
168
169
  const ttl = async (key) => {
169
- let result = null;
170
+ let result;
170
171
  if (nonBlocking) {
171
172
  try {
172
173
  result = await Promise.race(stores.map(async (store) => store.get(key, { raw: true })));
173
174
  if (result === void 0) {
174
- return null;
175
+ return void 0;
175
176
  }
176
177
  } catch (error) {
177
178
  eventEmitter.emit("ttl", { key, error });
@@ -193,7 +194,7 @@ var createCache = (options) => {
193
194
  if (result?.expires) {
194
195
  return result.expires;
195
196
  }
196
- return null;
197
+ return void 0;
197
198
  };
198
199
  const set = async (stores2, key, value, ttl2) => {
199
200
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cache-manager",
3
- "version": "6.4.3",
3
+ "version": "7.0.1",
4
4
  "description": "Cache Manager for Node.js",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -50,21 +50,21 @@
50
50
  ],
51
51
  "license": "MIT",
52
52
  "dependencies": {
53
- "keyv": "^5.3.3"
53
+ "keyv": "^5.3.4"
54
54
  },
55
55
  "devDependencies": {
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",
56
+ "@faker-js/faker": "^9.8.0",
57
+ "@keyv/redis": "^4.4.1",
58
+ "@types/node": "^24.0.6",
59
+ "@vitest/coverage-v8": "^3.2.4",
60
+ "@vitest/spy": "^3.2.4",
61
61
  "cache-manager-redis-yet": "^5.1.5",
62
62
  "rimraf": "^6.0.1",
63
- "tsup": "^8.4.0",
63
+ "tsup": "^8.5.0",
64
64
  "typescript": "^5.8.3",
65
- "vitest": "^3.1.3",
66
- "xo": "^0.60.0",
67
- "cacheable": "^1.9.0"
65
+ "vitest": "^3.2.4",
66
+ "xo": "^1.1.1",
67
+ "cacheable": "^1.10.0"
68
68
  },
69
69
  "xo": {
70
70
  "rules": {