cgserver 12.3.3 → 12.3.4
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
CHANGED
|
@@ -39,7 +39,7 @@ class CacheItem {
|
|
|
39
39
|
key = "";
|
|
40
40
|
value = null;
|
|
41
41
|
milliseconds = 0;
|
|
42
|
-
expire_time =
|
|
42
|
+
expire_time = new Date();
|
|
43
43
|
}
|
|
44
44
|
class CacheTool {
|
|
45
45
|
_items = {};
|
|
@@ -60,7 +60,7 @@ class CacheTool {
|
|
|
60
60
|
delete this._items[key];
|
|
61
61
|
continue;
|
|
62
62
|
}
|
|
63
|
-
if (time > item.expire_time) {
|
|
63
|
+
if (time > item.expire_time.getTime()) {
|
|
64
64
|
this.remove(key);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -70,13 +70,13 @@ class CacheTool {
|
|
|
70
70
|
if (!item) {
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
|
-
let
|
|
74
|
-
if (
|
|
73
|
+
let now = new Date().getTime();
|
|
74
|
+
if (now > item.expire_time.getTime()) {
|
|
75
75
|
this.remove(key);
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
if (refresh) {
|
|
79
|
-
item.expire_time =
|
|
79
|
+
item.expire_time = new Date(now + item.milliseconds);
|
|
80
80
|
}
|
|
81
81
|
return item.value;
|
|
82
82
|
}
|
|
@@ -95,7 +95,7 @@ class CacheTool {
|
|
|
95
95
|
}
|
|
96
96
|
item.value = value;
|
|
97
97
|
item.milliseconds = milliseconds;
|
|
98
|
-
item.expire_time = new Date(
|
|
98
|
+
item.expire_time = new Date(Date.now() + milliseconds);
|
|
99
99
|
}
|
|
100
100
|
remove(key) {
|
|
101
101
|
this._items[key] = null;
|
|
@@ -2,7 +2,7 @@ declare class CacheItem {
|
|
|
2
2
|
key: string;
|
|
3
3
|
value: any;
|
|
4
4
|
milliseconds: number;
|
|
5
|
-
expire_time:
|
|
5
|
+
expire_time: Date;
|
|
6
6
|
}
|
|
7
7
|
export declare class CacheTool {
|
|
8
8
|
protected _items: {
|
|
@@ -13,15 +13,15 @@ export declare class CacheTool {
|
|
|
13
13
|
* 定时清除缓存
|
|
14
14
|
*/
|
|
15
15
|
protected _refresh(): void;
|
|
16
|
-
get(key:
|
|
16
|
+
get(key: string, refresh?: boolean): any;
|
|
17
17
|
/**
|
|
18
18
|
*
|
|
19
19
|
* @param key
|
|
20
20
|
* @param value
|
|
21
21
|
* @param time 缓存的毫秒数
|
|
22
22
|
*/
|
|
23
|
-
add(key:
|
|
24
|
-
remove(key:
|
|
23
|
+
add(key: string, value: any, milliseconds: number): void;
|
|
24
|
+
remove(key: string): void;
|
|
25
25
|
}
|
|
26
26
|
export declare let gCacheTool: CacheTool;
|
|
27
27
|
export {};
|