cache-manager 6.1.1 → 6.1.2
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 +22 -22
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ If you are looking for older documentation you can find it here:
|
|
|
48
48
|
* [Contribute](#contribute)
|
|
49
49
|
* [License](#license)
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
# Installation
|
|
52
52
|
|
|
53
53
|
```sh
|
|
54
54
|
npm install cache-manager
|
|
@@ -67,7 +67,7 @@ npm install @keyv/etcd
|
|
|
67
67
|
```
|
|
68
68
|
In addition Keyv supports other storage adapters such as `lru-cache` and `CacheableMemory` from Cacheable (more examples below). Please read [Keyv document](https://keyv.org/docs/) for more information.
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
# Quick start
|
|
71
71
|
```typescript
|
|
72
72
|
import { Keyv } from 'keyv';
|
|
73
73
|
import { createCache } from 'cache-manager';
|
|
@@ -130,7 +130,7 @@ await cache.wrap('key', () => 'value')
|
|
|
130
130
|
// => value
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
# Using CacheableMemory or lru-cache as storage adapter
|
|
134
134
|
|
|
135
135
|
Because we are using [Keyv](https://keyv.org/), you can use any storage adapter that Keyv supports such as `lru-cache` or `CacheableMemory` from Cacheable. Below is an example of using `CacheableMemory`:
|
|
136
136
|
|
|
@@ -157,7 +157,7 @@ const keyv = new Keyv({ store: new LRU({ max: 5000, maxAge: 60000 }) });
|
|
|
157
157
|
const cache = createCache({ stores: [keyv] });
|
|
158
158
|
```
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
## Options
|
|
161
161
|
- **stores**?: Keyv[]
|
|
162
162
|
|
|
163
163
|
List of Keyv instance. Please refer to the [Keyv document](https://keyv.org/docs/#3.-create-a-new-keyv-instance) for more information.
|
|
@@ -177,8 +177,8 @@ const cache = createCache({ stores: [keyv] });
|
|
|
177
177
|
* `clear` - will not wait for all stores to finish.
|
|
178
178
|
* `wrap` - will do the same as `get` and `set` (return the first value found and not wait for all stores to finish).
|
|
179
179
|
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
# Methods
|
|
181
|
+
## set
|
|
182
182
|
`set(key, value, [ttl]): Promise<value>`
|
|
183
183
|
|
|
184
184
|
Sets a key value pair. It is possible to define a ttl (in milliseconds). An error will be throw on any failed
|
|
@@ -191,7 +191,7 @@ await cache.set('key 2', 'value 2', 5000)
|
|
|
191
191
|
```
|
|
192
192
|
See unit tests in [`test/set.test.ts`](./test/set.test.ts) for more information.
|
|
193
193
|
|
|
194
|
-
|
|
194
|
+
## mset
|
|
195
195
|
|
|
196
196
|
`mset(keys: [ { key, value, ttl } ]): Promise<true>`
|
|
197
197
|
|
|
@@ -204,7 +204,7 @@ await cache.mset([
|
|
|
204
204
|
]);
|
|
205
205
|
```
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
## get
|
|
208
208
|
`get(key): Promise<value>`
|
|
209
209
|
|
|
210
210
|
Gets a saved value from the cache. Returns a null if not found or expired. If the value was found it returns the value.
|
|
@@ -220,7 +220,7 @@ await cache.get('foo')
|
|
|
220
220
|
```
|
|
221
221
|
See unit tests in [`test/get.test.ts`](./test/get.test.ts) for more information.
|
|
222
222
|
|
|
223
|
-
|
|
223
|
+
## mget
|
|
224
224
|
|
|
225
225
|
`mget(keys: [key]): Promise<value[]>`
|
|
226
226
|
|
|
@@ -236,7 +236,7 @@ await cache.mget(['key-1', 'key-2', 'key-3'])
|
|
|
236
236
|
// => ['value 1', 'value 2', null]
|
|
237
237
|
```
|
|
238
238
|
|
|
239
|
-
|
|
239
|
+
## del
|
|
240
240
|
`del(key): Promise<true>`
|
|
241
241
|
|
|
242
242
|
Delete a key, an error will be throw on any failed.
|
|
@@ -254,7 +254,7 @@ await cache.get('key')
|
|
|
254
254
|
```
|
|
255
255
|
See unit tests in [`test/del.test.ts`](./test/del.test.ts) for more information.
|
|
256
256
|
|
|
257
|
-
|
|
257
|
+
## mdel
|
|
258
258
|
|
|
259
259
|
`mdel(keys: [key]): Promise<true>`
|
|
260
260
|
|
|
@@ -269,7 +269,7 @@ await cache.mset([
|
|
|
269
269
|
await cache.mdel(['key-1', 'key-2'])
|
|
270
270
|
```
|
|
271
271
|
|
|
272
|
-
|
|
272
|
+
## clear
|
|
273
273
|
`clear(): Promise<true>`
|
|
274
274
|
|
|
275
275
|
Flush all data, an error will be throw on any failed.
|
|
@@ -292,7 +292,7 @@ await cache.get('key-2')
|
|
|
292
292
|
```
|
|
293
293
|
See unit tests in [`test/clear.test.ts`](./test/clear.test.ts) for more information.
|
|
294
294
|
|
|
295
|
-
|
|
295
|
+
## wrap
|
|
296
296
|
`wrap(key, fn: async () => value, [ttl], [refreshThreshold]): Promise<value>`
|
|
297
297
|
|
|
298
298
|
Wraps a function in cache. The first time the function is run, its results are stored in cache so subsequent calls retrieve from cache instead of calling the function.
|
|
@@ -332,8 +332,8 @@ 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
|
-
|
|
336
|
-
|
|
335
|
+
# Events
|
|
336
|
+
## set
|
|
337
337
|
Fired when a key has been added or changed.
|
|
338
338
|
|
|
339
339
|
```ts
|
|
@@ -342,7 +342,7 @@ cache.on('set', ({ key, value, error }) => {
|
|
|
342
342
|
})
|
|
343
343
|
```
|
|
344
344
|
|
|
345
|
-
|
|
345
|
+
## del
|
|
346
346
|
Fired when a key has been removed manually.
|
|
347
347
|
|
|
348
348
|
```ts
|
|
@@ -351,7 +351,7 @@ cache.on('del', ({ key, error }) => {
|
|
|
351
351
|
})
|
|
352
352
|
```
|
|
353
353
|
|
|
354
|
-
|
|
354
|
+
## clear
|
|
355
355
|
Fired when the cache has been flushed.
|
|
356
356
|
|
|
357
357
|
```ts
|
|
@@ -362,7 +362,7 @@ cache.on('clear', (error) => {
|
|
|
362
362
|
})
|
|
363
363
|
```
|
|
364
364
|
|
|
365
|
-
|
|
365
|
+
## refresh
|
|
366
366
|
Fired when the cache has been refreshed in the background.
|
|
367
367
|
|
|
368
368
|
```ts
|
|
@@ -375,11 +375,11 @@ cache.on('refresh', ({ key, value, error }) => {
|
|
|
375
375
|
|
|
376
376
|
See unit tests in [`test/events.test.ts`](./test/events.test.ts) for more information.
|
|
377
377
|
|
|
378
|
-
|
|
378
|
+
# Update on redis and ioredis Support
|
|
379
379
|
|
|
380
380
|
We will not be supporting `cache-manager-ioredis-yet` or `cache-manager-redis-yet` in the future as we have moved to using `Keyv` as the storage adapter `@keyv/redis`.
|
|
381
381
|
|
|
382
|
-
|
|
382
|
+
# Using Legacy Storage Adapters
|
|
383
383
|
|
|
384
384
|
There are many storage adapters built for `cache-manager` and because of that we wanted to provide a way to use them with `KeyvAdapter`. Below is an example of using `cache-manager-redis-yet`:
|
|
385
385
|
|
|
@@ -396,10 +396,10 @@ const cache = createCache({
|
|
|
396
396
|
|
|
397
397
|
This adapter will allow you to add in any storage adapter. If there are issues it needs to follow `CacheManagerStore` interface.
|
|
398
398
|
|
|
399
|
-
|
|
399
|
+
# Contribute
|
|
400
400
|
|
|
401
401
|
If you would like to contribute to the project, please read how to contribute here [CONTRIBUTING.md](https://github.com/jaredwray/cacheable/blob/main/CONTRIBUTING.md).
|
|
402
402
|
|
|
403
|
-
|
|
403
|
+
# License
|
|
404
404
|
|
|
405
405
|
[MIT © Jared Wray ](./LICENSE)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cache-manager",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.2",
|
|
4
4
|
"description": "Cache Manager for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -50,17 +50,17 @@
|
|
|
50
50
|
],
|
|
51
51
|
"license": "MIT",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"keyv": "^5.1.
|
|
53
|
+
"keyv": "^5.1.2"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@faker-js/faker": "^9.0
|
|
56
|
+
"@faker-js/faker": "^9.1.0",
|
|
57
57
|
"@keyv/redis": "^3.0.1",
|
|
58
|
-
"@types/node": "^22.
|
|
58
|
+
"@types/node": "^22.8.1",
|
|
59
59
|
"@vitest/coverage-v8": "^2.1.3",
|
|
60
60
|
"cache-manager-redis-yet": "^5.1.5",
|
|
61
|
-
"cacheable": "^1.8.
|
|
61
|
+
"cacheable": "^1.8.1",
|
|
62
62
|
"rimraf": "^6.0.1",
|
|
63
|
-
"tsup": "^8.3.
|
|
63
|
+
"tsup": "^8.3.5",
|
|
64
64
|
"typescript": "^5.6.3",
|
|
65
65
|
"vitest": "^2.1.3",
|
|
66
66
|
"xo": "^0.59.3"
|