@jayfong/x-server 1.34.5 → 1.34.6
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.
|
@@ -27,7 +27,7 @@ class CacheService {
|
|
|
27
27
|
*
|
|
28
28
|
* @param key 键
|
|
29
29
|
* @param value 值
|
|
30
|
-
* @param ttl
|
|
30
|
+
* @param ttl 缓存时间
|
|
31
31
|
* @returns 返回设置的缓存内容
|
|
32
32
|
*/
|
|
33
33
|
|
|
@@ -36,8 +36,12 @@ class CacheService {
|
|
|
36
36
|
const redisKey = this.toRedisKey(key);
|
|
37
37
|
const redisValue = JSON.stringify(value);
|
|
38
38
|
const redisTtl = typeof ttl === 'function' ? ttl(value, this.options.ttl) : ttl;
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
|
|
40
|
+
if (redisTtl) {
|
|
41
|
+
await _x.x.redis.set(redisKey, redisValue, // 毫秒
|
|
42
|
+
'PX', (0, _date.ms)(redisTtl));
|
|
43
|
+
}
|
|
44
|
+
|
|
41
45
|
return value;
|
|
42
46
|
}
|
|
43
47
|
/**
|
|
@@ -100,7 +104,7 @@ class CacheService {
|
|
|
100
104
|
*
|
|
101
105
|
* @param key 键
|
|
102
106
|
* @param action 获取缓存内容的操作
|
|
103
|
-
* @param ttl
|
|
107
|
+
* @param ttl 缓存时间
|
|
104
108
|
* @returns 返回获取到的内容
|
|
105
109
|
*/
|
|
106
110
|
|
package/lib/services/cache.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare class CacheService<TData extends Data = Data, TKey extends Key<TD
|
|
|
27
27
|
*
|
|
28
28
|
* @param key 键
|
|
29
29
|
* @param value 值
|
|
30
|
-
* @param ttl
|
|
30
|
+
* @param ttl 缓存时间
|
|
31
31
|
* @returns 返回设置的缓存内容
|
|
32
32
|
*/
|
|
33
33
|
set<K extends TKeyPath, V extends Value<TData, K>>(key: K, value: V, ttl?: MsValue | ((data: V, defaultTTL: MsValue) => MsValue)): Promise<V>;
|
|
@@ -57,7 +57,7 @@ export declare class CacheService<TData extends Data = Data, TKey extends Key<TD
|
|
|
57
57
|
*
|
|
58
58
|
* @param key 键
|
|
59
59
|
* @param action 获取缓存内容的操作
|
|
60
|
-
* @param ttl
|
|
60
|
+
* @param ttl 缓存时间
|
|
61
61
|
* @returns 返回获取到的内容
|
|
62
62
|
*/
|
|
63
63
|
remember<K extends TKeyPath, V extends Value<TData, K>>(key: K, action: () => V | Promise<V>, ttl?: MsValue | ((data: V, defaultTTL: MsValue) => MsValue)): Promise<V>;
|
package/lib/services/cache.js
CHANGED
|
@@ -17,7 +17,7 @@ export class CacheService {
|
|
|
17
17
|
*
|
|
18
18
|
* @param key 键
|
|
19
19
|
* @param value 值
|
|
20
|
-
* @param ttl
|
|
20
|
+
* @param ttl 缓存时间
|
|
21
21
|
* @returns 返回设置的缓存内容
|
|
22
22
|
*/
|
|
23
23
|
|
|
@@ -26,8 +26,12 @@ export class CacheService {
|
|
|
26
26
|
const redisKey = this.toRedisKey(key);
|
|
27
27
|
const redisValue = JSON.stringify(value);
|
|
28
28
|
const redisTtl = typeof ttl === 'function' ? ttl(value, this.options.ttl) : ttl;
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
|
|
30
|
+
if (redisTtl) {
|
|
31
|
+
await x.redis.set(redisKey, redisValue, // 毫秒
|
|
32
|
+
'PX', ms(redisTtl));
|
|
33
|
+
}
|
|
34
|
+
|
|
31
35
|
return value;
|
|
32
36
|
}
|
|
33
37
|
/**
|
|
@@ -90,7 +94,7 @@ export class CacheService {
|
|
|
90
94
|
*
|
|
91
95
|
* @param key 键
|
|
92
96
|
* @param action 获取缓存内容的操作
|
|
93
|
-
* @param ttl
|
|
97
|
+
* @param ttl 缓存时间
|
|
94
98
|
* @returns 返回获取到的内容
|
|
95
99
|
*/
|
|
96
100
|
|