ti2 1.0.66 → 1.0.68
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/cache.js +32 -14
- package/controllers/user.js +1 -0
- package/index.js +7 -1
- package/package.json +1 -1
package/cache.js
CHANGED
|
@@ -11,12 +11,13 @@ const save = async ({
|
|
|
11
11
|
value,
|
|
12
12
|
ttl = defaultTTL,
|
|
13
13
|
}) => {
|
|
14
|
-
const key = `${pluginName}:${
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}))
|
|
14
|
+
const key = `${pluginName}:${(() => {
|
|
15
|
+
if (typeof keyParam !== 'string') {
|
|
16
|
+
return hash(keyParam);
|
|
17
|
+
}
|
|
18
|
+
return keyParam;
|
|
19
|
+
})()}`;
|
|
20
|
+
await cache.set(key, JSON.stringify(value));
|
|
20
21
|
await cache.expire(key, ttl);
|
|
21
22
|
};
|
|
22
23
|
|
|
@@ -24,14 +25,15 @@ const get = async ({
|
|
|
24
25
|
pluginName,
|
|
25
26
|
key: keyParam,
|
|
26
27
|
}) => {
|
|
27
|
-
const key = `${pluginName}:${
|
|
28
|
+
const key = `${pluginName}:${(() => {
|
|
29
|
+
if (typeof keyParam !== 'string') {
|
|
30
|
+
return hash(keyParam);
|
|
31
|
+
}
|
|
32
|
+
return keyParam;
|
|
33
|
+
})()}`;
|
|
28
34
|
const storeVal = await cache.get(key);
|
|
29
35
|
if (!storeVal) return storeVal;
|
|
30
|
-
|
|
31
|
-
if (keyType === 'string') {
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
return JSON.parse(value);
|
|
36
|
+
return JSON.parse(storeVal);
|
|
35
37
|
};
|
|
36
38
|
|
|
37
39
|
const getOrExec = async ({
|
|
@@ -41,7 +43,15 @@ const getOrExec = async ({
|
|
|
41
43
|
fn,
|
|
42
44
|
fnParams,
|
|
43
45
|
}) => {
|
|
44
|
-
const key =
|
|
46
|
+
const key = (() => {
|
|
47
|
+
if (!keyParam) {
|
|
48
|
+
return hash({ fn, fnParams });
|
|
49
|
+
}
|
|
50
|
+
if (typeof keyParam !== 'string') {
|
|
51
|
+
return hash(keyParam);
|
|
52
|
+
}
|
|
53
|
+
return keyParam;
|
|
54
|
+
})();
|
|
45
55
|
let value = await get({ pluginName, key });
|
|
46
56
|
if (value !== null) return value;
|
|
47
57
|
value = await fn(...fnParams);
|
|
@@ -60,7 +70,15 @@ const drop = async ({
|
|
|
60
70
|
fn,
|
|
61
71
|
fnParams,
|
|
62
72
|
}) => {
|
|
63
|
-
|
|
73
|
+
const key = `${pluginName}:${(() => {
|
|
74
|
+
if (!keyParam) {
|
|
75
|
+
return hash({ fn, fnParams });
|
|
76
|
+
}
|
|
77
|
+
if (typeof keyParam !== 'string') {
|
|
78
|
+
return hash(keyParam);
|
|
79
|
+
}
|
|
80
|
+
return keyParam;
|
|
81
|
+
})()}`;
|
|
64
82
|
key = `${pluginName}:${key}`;
|
|
65
83
|
await cache.del(key);
|
|
66
84
|
};
|
package/controllers/user.js
CHANGED
package/index.js
CHANGED
|
@@ -79,8 +79,14 @@ module.exports = async ({
|
|
|
79
79
|
params[nuName] = value;
|
|
80
80
|
});
|
|
81
81
|
const pluginInstance = await new Plugin({
|
|
82
|
-
|
|
82
|
+
cache: {
|
|
83
|
+
drop: args => cache.getOrExec({ ...args, pluginName }),
|
|
84
|
+
get: args => cache.getOrExec({ ...args, pluginName }),
|
|
85
|
+
getOrExec: args => cache.getOrExec({ ...args, pluginName }),
|
|
86
|
+
save: args => cache.getOrExec({ ...args, pluginName }),
|
|
87
|
+
},
|
|
83
88
|
events: ti2Events,
|
|
89
|
+
name: pluginName,
|
|
84
90
|
...params,
|
|
85
91
|
});
|
|
86
92
|
return pluginInstance;
|