@zenweb/cache 4.2.2 → 4.3.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/dist/cache.js CHANGED
@@ -138,7 +138,7 @@ class Cache {
138
138
  // 使用锁设置缓存
139
139
  let locker;
140
140
  let refresh = opt.refresh || false; // 强制刷新
141
- let retryCount = typeof opt.retryCount === 'number' ? opt.retryCount : 100;
141
+ let retryCount = typeof opt.retryCount === 'number' ? opt.retryCount : 10;
142
142
  while (true) {
143
143
  if (!refresh) {
144
144
  // 尝试从 redis 中获取
package/dist/types.d.ts CHANGED
@@ -89,7 +89,9 @@ export interface LockOption {
89
89
  lockTimeout?: number;
90
90
  /**
91
91
  * 锁获取失败重试次数
92
- * @default 100
92
+ * - 0 不进行重试
93
+ * - lockGet 默认为 10
94
+ * - singleRunner 默认为 0
93
95
  */
94
96
  retryCount?: number;
95
97
  /**
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- /// <reference types="debug" />
2
1
  import { Redis, RedisKey, RedisValue } from 'ioredis';
3
- export declare const debug: import("debug").Debugger;
2
+ export declare const debug: import("@zenweb/core").Debugger;
4
3
  /**
5
4
  * Promise 等待
6
5
  * @param ms 毫秒
@@ -21,4 +20,4 @@ export declare function runRedisScript(redis: Redis, hash: string, script: strin
21
20
  * 生成一个参数缓存key
22
21
  * - 多个元素用 : 连接
23
22
  */
24
- export declare function normalKey(...key: (string | number | object)[]): string;
23
+ export declare function cacheKey(...key: (string | number | object)[]): string;
package/dist/utils.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalKey = exports.runRedisScript = exports.sleep = exports.debug = void 0;
4
- const debug_1 = require("debug");
3
+ exports.cacheKey = exports.runRedisScript = exports.sleep = exports.debug = void 0;
4
+ const core_1 = require("@zenweb/core");
5
5
  const crypto = require("crypto");
6
- exports.debug = (0, debug_1.default)('zenweb:cache');
6
+ exports.debug = (0, core_1.zenwebDebug)('cache');
7
7
  /**
8
8
  * Promise 等待
9
9
  * @param ms 毫秒
@@ -69,11 +69,11 @@ function plainifyOrHash(obj) {
69
69
  * 生成一个参数缓存key
70
70
  * - 多个元素用 : 连接
71
71
  */
72
- function normalKey(...key) {
72
+ function cacheKey(...key) {
73
73
  return key.map(i => {
74
74
  if (typeof i === 'string')
75
75
  return i;
76
76
  return plainifyOrHash(i);
77
77
  }).join(':');
78
78
  }
79
- exports.normalKey = normalKey;
79
+ exports.cacheKey = cacheKey;
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@zenweb/cache",
3
- "version": "4.2.2",
3
+ "packageManager": "yarn@4.0.2",
4
+ "version": "4.3.1",
4
5
  "description": "Zenweb Cache module",
5
6
  "exports": "./dist/index.js",
6
7
  "types": "./dist/index.d.ts",
@@ -8,10 +9,11 @@
8
9
  "dist"
9
10
  ],
10
11
  "scripts": {
12
+ "vscode": "yarn dlx @yarnpkg/sdks vscode",
11
13
  "build": "rimraf dist && tsc",
12
- "prepublishOnly": "npm run build",
14
+ "prepublishOnly": "yarn run build",
13
15
  "test": "ts-mocha -p tsconfig.json test/**/*.test.ts",
14
- "dev": "cd example && cross-env DEBUG=* NODE_ENV=development ts-node app"
16
+ "dev": "cd example && cross-env DEBUG=\\* NODE_ENV=development ts-node app"
15
17
  },
16
18
  "author": {
17
19
  "name": "YeFei",
@@ -31,16 +33,17 @@
31
33
  "homepage": "https://zenweb.node.ltd/docs/modules/cache",
32
34
  "devDependencies": {
33
35
  "@types/mocha": "^10.0.1",
36
+ "@types/node": "^20.10.6",
34
37
  "cross-env": "^7.0.3",
35
38
  "mocha": "^10.2.0",
36
39
  "rimraf": "^4.3.1",
37
40
  "ts-mocha": "^10.0.0",
38
41
  "ts-node": "^10.9.1",
39
- "typescript": "^5.1.6",
40
- "zenweb": "^4.0.1"
42
+ "typescript": "^5.3.3",
43
+ "zenweb": "^4.2.7"
41
44
  },
42
45
  "dependencies": {
43
- "debug": "^4.3.4",
46
+ "@zenweb/core": "^4.2.3",
44
47
  "ioredis": "^5.3.2"
45
48
  }
46
49
  }
package/CHANGELOG.md DELETED
@@ -1,28 +0,0 @@
1
- # Changelog
2
-
3
- ## [4.2.2] - 2023-8-23
4
- 修改: 除了 Buffer 类型意外全部都使用 JSON 序列化
5
-
6
- ## [4.2.1] - 2023-8-23
7
- fix: 内容未压缩,客户端支持压缩内容时却标识为压缩内容
8
-
9
- ## [4.2.0] - 2023-8-22
10
- 更新: cached 中间件支持 null key,不使用缓存
11
-
12
- ## [4.1.3] - 2023-8-21
13
- fix: 二次获取缓存数据时会返回压缩数据的问题
14
-
15
- ## [4.1.2] - 2023-8-21
16
- fix: 首次缓存新数据时会返回压缩数据的问题
17
-
18
- ## [4.1.1] - 2023-8-18
19
- 增加 normalKey number 参数
20
-
21
- ## [4.1.0] - 2023-8-18
22
- 增加 normalKey 方法
23
-
24
- ## [4.0.1] - 2023-8-17
25
- cached 中间件增加 type 参数
26
-
27
- ## [4.0.0] - 2023-8-8
28
- 发布