cache-manager 6.1.0 → 6.1.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 +14 -10
- package/package.json +12 -9
package/README.md
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
[<img align="center" src="https://cacheable.org/
|
|
1
|
+
[<img align="center" src="https://cacheable.org/symbol.svg" alt="Cacheable" />](https://github.com/jaredwray/cacheable)
|
|
2
2
|
|
|
3
3
|
# cache-manager
|
|
4
4
|
[](https://codecov.io/gh/jaredwray/cacheable)
|
|
5
5
|
[](https://github.com/jaredwray/cacheable/actions/workflows/tests.yml)
|
|
6
|
-
[](https://github.com/jaredwray/cacheable/blob/main/LICENSE)
|
|
7
6
|
[](https://npmjs.com/package/cache-manager)
|
|
8
|
-

|
|
7
|
+
[](https://npmjs.com/package/cache-manager)
|
|
8
|
+
[](https://github.com/jaredwray/cacheable/blob/main/LICENSE)
|
|
9
9
|
|
|
10
10
|
# Simple and fast NodeJS caching module.
|
|
11
11
|
A cache module for NodeJS that allows easy wrapping of functions in cache, tiered caches, and a consistent interface.
|
|
12
12
|
- Made with Typescript and compatible with [ESModules](https://nodejs.org/docs/latest-v14.x/api/esm.html).
|
|
13
13
|
- Easy way to wrap any function in cache, supports a mechanism to refresh expiring cache keys in background.
|
|
14
14
|
- Tiered caches -- data gets stored in each cache and fetched from the highest priority cache(s) first.
|
|
15
|
+
- `nonBlocking` option that optimizes how the system handles multiple stores.
|
|
15
16
|
- Use with any [Keyv](https://keyv.org/) compatible storage adapter.
|
|
16
17
|
- 100% test coverage via [vitest](https://github.com/vitest-dev/vitest).
|
|
17
18
|
|
|
@@ -27,6 +28,7 @@ If you are looking for older documentation you can find it here:
|
|
|
27
28
|
* [Installation](#installation)
|
|
28
29
|
* [Quick start](#quick-start)
|
|
29
30
|
* [Using `CacheableMemory` or `lru-cache` as storage adapter](#using-cacheablememory-or-lru-cache-as-storage-adapter)
|
|
31
|
+
* [Options](#options)
|
|
30
32
|
* [Methods](#methods)
|
|
31
33
|
* [.set](#set)
|
|
32
34
|
* [.mset](#mset)
|
|
@@ -82,7 +84,7 @@ Here is an example of doing layer 1 and layer 2 caching with the in-memory being
|
|
|
82
84
|
|
|
83
85
|
```ts
|
|
84
86
|
import { Keyv } from 'keyv';
|
|
85
|
-
import
|
|
87
|
+
import KeyvRedis from '@keyv/redis';
|
|
86
88
|
import { CacheableMemory } from 'cacheable';
|
|
87
89
|
import { createCache } from 'cache-manager';
|
|
88
90
|
|
|
@@ -136,10 +138,11 @@ In this example we are using `CacheableMemory` from Cacheable which is a fast in
|
|
|
136
138
|
|
|
137
139
|
```ts
|
|
138
140
|
import { createCache } from 'cache-manager';
|
|
139
|
-
import {Keyv} from 'keyv';
|
|
140
|
-
import {
|
|
141
|
+
import { Keyv } from 'keyv';
|
|
142
|
+
import { KeyvCacheableMemory } from 'cacheable';
|
|
141
143
|
|
|
142
|
-
const
|
|
144
|
+
const store = new KeyvCacheableMemory({ ttl: 60000, lruSize: 5000 });
|
|
145
|
+
const keyv = new Keyv({ store });
|
|
143
146
|
const cache = createCache({ stores: [keyv] });
|
|
144
147
|
```
|
|
145
148
|
|
|
@@ -167,17 +170,18 @@ const cache = createCache({ stores: [keyv] });
|
|
|
167
170
|
|
|
168
171
|
- **nonBlocking**?: boolean - Default false
|
|
169
172
|
|
|
170
|
-
If set to true, the system will not block when multiple stores are used. Here is how it affects
|
|
173
|
+
If set to true, the system will not block when multiple stores are used. Here is how it affects the type of functions:
|
|
171
174
|
* `set and mset` - will not wait for all stores to finish.
|
|
172
175
|
* `get and mget` - will return the first (fastest) value found.
|
|
173
176
|
* `del and mdel` - will not wait for all stores to finish.
|
|
174
177
|
* `clear` - will not wait for all stores to finish.
|
|
178
|
+
* `wrap` - will do the same as `get` and `set` (return the first value found and not wait for all stores to finish).
|
|
175
179
|
|
|
176
180
|
## Methods
|
|
177
181
|
### set
|
|
178
182
|
`set(key, value, [ttl]): Promise<value>`
|
|
179
183
|
|
|
180
|
-
Sets a key value pair. It is possible to define a ttl (in
|
|
184
|
+
Sets a key value pair. It is possible to define a ttl (in milliseconds). An error will be throw on any failed
|
|
181
185
|
|
|
182
186
|
```ts
|
|
183
187
|
await cache.set('key-1', 'value 1')
|
|
@@ -191,7 +195,7 @@ See unit tests in [`test/set.test.ts`](./test/set.test.ts) for more information.
|
|
|
191
195
|
|
|
192
196
|
`mset(keys: [ { key, value, ttl } ]): Promise<true>`
|
|
193
197
|
|
|
194
|
-
Sets multiple key value pairs. It is possible to define a ttl (in
|
|
198
|
+
Sets multiple key value pairs. It is possible to define a ttl (in milliseconds). An error will be throw on any failed
|
|
195
199
|
|
|
196
200
|
```ts
|
|
197
201
|
await cache.mset([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cache-manager",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"description": "Cache Manager for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
],
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/jaredwray/cacheable.git"
|
|
21
|
+
"url": "git+https://github.com/jaredwray/cacheable.git",
|
|
22
|
+
"directory": "packages/cache-manager"
|
|
22
23
|
},
|
|
23
24
|
"keywords": [
|
|
24
25
|
"cache",
|
|
@@ -49,17 +50,19 @@
|
|
|
49
50
|
],
|
|
50
51
|
"license": "MIT",
|
|
51
52
|
"dependencies": {
|
|
52
|
-
"keyv": "^5.0
|
|
53
|
+
"keyv": "^5.1.0"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"@faker-js/faker": "^9.0.
|
|
56
|
-
"@
|
|
57
|
-
"@
|
|
56
|
+
"@faker-js/faker": "^9.0.3",
|
|
57
|
+
"@keyv/redis": "^3.0.1",
|
|
58
|
+
"@types/node": "^22.7.5",
|
|
59
|
+
"@vitest/coverage-v8": "^2.1.3",
|
|
58
60
|
"cache-manager-redis-yet": "^5.1.5",
|
|
61
|
+
"cacheable": "^1.8.0",
|
|
59
62
|
"rimraf": "^6.0.1",
|
|
60
63
|
"tsup": "^8.3.0",
|
|
61
|
-
"typescript": "^5.6.
|
|
62
|
-
"vitest": "^2.1.
|
|
64
|
+
"typescript": "^5.6.3",
|
|
65
|
+
"vitest": "^2.1.3",
|
|
63
66
|
"xo": "^0.59.3"
|
|
64
67
|
},
|
|
65
68
|
"xo": {
|
|
@@ -71,7 +74,7 @@
|
|
|
71
74
|
"scripts": {
|
|
72
75
|
"clean": "rimraf ./dist ./coverage ./node_modules",
|
|
73
76
|
"test": "xo --fix && vitest run --coverage",
|
|
74
|
-
"test:ci": "xo && vitest run
|
|
77
|
+
"test:ci": "xo && vitest run",
|
|
75
78
|
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean"
|
|
76
79
|
}
|
|
77
80
|
}
|