cgserver 12.3.3 → 12.3.5

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
@@ -1,4 +1,8 @@
1
1
  # 版本更新日志
2
+ ## v12.3.4
3
+ - 取消所有默认创建的index
4
+ ## v12.3.4
5
+ - cache的过期时间修改
2
6
  ## v12.3.3
3
7
  - redis 相关语法提示问题
4
8
  - 支付宝接口增强
@@ -39,7 +39,7 @@ class CacheItem {
39
39
  key = "";
40
40
  value = null;
41
41
  milliseconds = 0;
42
- expire_time = -1;
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 time = new Date().getTime();
74
- if (time > item.expire_time) {
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 = time + item.milliseconds;
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().getTime() + milliseconds;
98
+ item.expire_time = new Date(Date.now() + milliseconds);
99
99
  }
100
100
  remove(key) {
101
101
  this._items[key] = null;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.gMongoCacheSer = exports.MongoCacheService = exports.MongoCacheModel = void 0;
4
4
  const MongoBaseService_1 = require("../Database/Mongo/MongoBaseService");
5
5
  const MongoManager_1 = require("../Database/Mongo/MongoManager");
6
- const cgserver_1 = require("../cgserver");
7
6
  //暂时就用这个了,反正没啥用户
8
7
  class MongoCacheModel extends MongoManager_1.MongoBaseModel {
9
8
  key = "";
@@ -16,17 +15,6 @@ exports.MongoCacheModel = MongoCacheModel;
16
15
  * 可以用来缓存kv数据
17
16
  */
18
17
  class MongoCacheService extends MongoBaseService_1.MongoBaseService {
19
- constructor(table, type, dbname = "") {
20
- super(table, type, dbname);
21
- cgserver_1.gCgServer.addListener("start", () => {
22
- if (!this.mongoDb) {
23
- //客户端未开启mongo
24
- return;
25
- }
26
- this.createIndex({ key: 1 });
27
- this.createIndex({ expireAt: 1 }, { expireAfterSeconds: 0 });
28
- });
29
- }
30
18
  async getData(key) {
31
19
  let cm = await this.findOne({ key: key });
32
20
  if (!cm) {
@@ -2,7 +2,7 @@ declare class CacheItem {
2
2
  key: string;
3
3
  value: any;
4
4
  milliseconds: number;
5
- expire_time: number;
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: any, refresh?: boolean): any;
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: any, value: any, milliseconds: any): void;
24
- remove(key: any): void;
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 {};
@@ -10,9 +10,6 @@ export declare class MongoCacheModel extends MongoBaseModel {
10
10
  * 可以用来缓存kv数据
11
11
  */
12
12
  export declare class MongoCacheService extends MongoBaseService<MongoCacheModel> {
13
- constructor(table: string, type: {
14
- new (): MongoCacheModel;
15
- }, dbname?: string);
16
13
  getData(key: string): Promise<any>;
17
14
  addData(key: string, data: any, expireAt?: number): Promise<MongoCacheModel>;
18
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "12.3.3",
3
+ "version": "12.3.5",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",