@keyvhq/memoize 1.2.6 → 1.5.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 +2 -2
- package/package.json +4 -6
- package/src/index.js +1 -16
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# @keyvhq/memoize [<img width="100" align="right" src="https://
|
|
1
|
+
# @keyvhq/memoize [<img width="100" align="right" src="https://keyv.js.org/media/logo-sunset.svg" alt="keyv">](https://github.com/microlinkhq/keyv)
|
|
2
2
|
|
|
3
3
|
> Memoize any function using Keyv as storage backend.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```shell
|
|
8
|
-
npm install --save
|
|
8
|
+
npm install --save @keyvhq/memoize
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@keyvhq/memoize",
|
|
3
3
|
"description": "Memoize any function using Keyv as storage backend.",
|
|
4
4
|
"homepage": "https://keyv.js.org",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.5.1",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -27,10 +27,8 @@
|
|
|
27
27
|
"value"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@keyvhq/core": "^1.
|
|
31
|
-
"
|
|
32
|
-
"mimic-fn": "~3.0.0",
|
|
33
|
-
"p-any": "~2.1.0"
|
|
30
|
+
"@keyvhq/core": "^1.4.0",
|
|
31
|
+
"mimic-fn": "~3.0.0"
|
|
34
32
|
},
|
|
35
33
|
"devDependencies": {
|
|
36
34
|
"ava": "latest",
|
|
@@ -50,5 +48,5 @@
|
|
|
50
48
|
"publishConfig": {
|
|
51
49
|
"access": "public"
|
|
52
50
|
},
|
|
53
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "2abf6dd067c6a7a7dbe5ec54c587f315d95f9160"
|
|
54
52
|
}
|
package/src/index.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const Keyv = require('@keyvhq/core')
|
|
4
4
|
const mimicFn = require('mimic-fn')
|
|
5
|
-
const pAny = require('p-any')
|
|
6
5
|
|
|
7
6
|
const isFunction = input => typeof input === 'function'
|
|
8
7
|
const isNumber = input => typeof input === 'number'
|
|
@@ -43,18 +42,6 @@ function memoize (
|
|
|
43
42
|
return isString(raw) ? keyv.deserialize(raw) : raw
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
/**
|
|
47
|
-
* @param {string} key
|
|
48
|
-
* @return {Promise<*>} value
|
|
49
|
-
* @throws if not found
|
|
50
|
-
*/
|
|
51
|
-
function getStoredValue (key) {
|
|
52
|
-
return getRaw(key).then(data => {
|
|
53
|
-
if (!data || isUndefined(data)) throw new Error('Not found')
|
|
54
|
-
return data.value
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
45
|
/**
|
|
59
46
|
* @param {string} key
|
|
60
47
|
* @param {*} value
|
|
@@ -73,9 +60,7 @@ function memoize (
|
|
|
73
60
|
const rawKey = getKey(...args)
|
|
74
61
|
const [key, forceExpiration] = Array.isArray(rawKey) ? rawKey : [rawKey]
|
|
75
62
|
|
|
76
|
-
if (!isUndefined(pending[key]))
|
|
77
|
-
return pAny([getStoredValue(key), pending[key]])
|
|
78
|
-
}
|
|
63
|
+
if (!isUndefined(pending[key])) return pending[key]
|
|
79
64
|
|
|
80
65
|
pending[key] = getRaw(key).then(async data => {
|
|
81
66
|
const hasValue = data ? !isUndefined(data.value) : false
|