koatty_cacheable 1.3.7 → 1.4.0

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/CHANGELOG.md CHANGED
@@ -2,4 +2,16 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [1.4.0](https://github.com/thinkkoa/koatty_cacheable/compare/v1.3.8...v1.4.0) (2023-02-18)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * cache subkey ([408e3c7](https://github.com/thinkkoa/koatty_cacheable/commit/408e3c709a4dfff6e7d224a22d26e58854a805ac))
11
+ * 启动时链接 ([e7ec709](https://github.com/thinkkoa/koatty_cacheable/commit/e7ec7094be106e4e48783c9b214b8369e8a18297))
12
+ * 支持引入变量做缓存key ([4ce81aa](https://github.com/thinkkoa/koatty_cacheable/commit/4ce81aaaf9610f4a62ddf43e3c4389dd003c2db8))
13
+ * 获取单例 ([0759972](https://github.com/thinkkoa/koatty_cacheable/commit/0759972adf7e86312f60f0bf77604bddf06ce0de))
14
+
15
+ ### [1.3.8](https://github.com/thinkkoa/koatty_cacheable/compare/v1.3.6...v1.3.8) (2023-01-13)
16
+
5
17
  ### [1.3.7](https://github.com/thinkkoa/koatty_cacheable/compare/v1.3.6...v1.3.7) (2022-05-27)
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2022-05-27 11:35:52
3
+ * @Date: 2023-02-19 01:22:50
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -15,20 +15,50 @@ import { CacheStore } from 'koatty_store';
15
15
  *
16
16
  * @export
17
17
  * @param {string} cacheName cache name
18
- * @param {number} [timeout=3600] cache timeout
18
+ * @param {CacheAbleOpt} [opt] cache options
19
+ * e.g:
20
+ * {
21
+ * params: ["id"],
22
+ * timeout: 30
23
+ * }
24
+ * Use the 'id' parameters of the method as cache subkeys, the cache expiration time 30s
19
25
  * @returns {MethodDecorator}
20
26
  */
21
- export declare function CacheAble(cacheName: string, timeout?: number): MethodDecorator;
27
+ export declare function CacheAble(cacheName: string, opt?: CacheAbleOpt): MethodDecorator;
28
+
29
+ /**
30
+ * @description:
31
+ * @return {*}
32
+ */
33
+ export declare interface CacheAbleOpt {
34
+ params?: string[];
35
+ timeout?: number;
36
+ }
22
37
 
23
38
  /**
24
39
  * Decorating the execution of this method will trigger a cache clear operation. Redis server config from db.ts.
25
40
  *
26
41
  * @export
27
42
  * @param {string} cacheName cacheName cache name
28
- * @param {eventTimes} [eventTime="Before"]
43
+ * @param {CacheEvictOpt} [opt] cache options
44
+ * e.g:
45
+ * {
46
+ * params: ["id"],
47
+ * eventTime: "Before"
48
+ * }
49
+ * Use the 'id' parameters of the method as cache subkeys, and clear the cache before the method executed
29
50
  * @returns
30
51
  */
31
- export declare function CacheEvict(cacheName: string, eventTime?: eventTimes): (target: any, methodName: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
52
+ export declare function CacheEvict(cacheName: string, opt?: CacheEvictOpt): (target: any, methodName: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
53
+
54
+ /**
55
+ * @description:
56
+ * @return {*}
57
+ */
58
+ export declare interface CacheEvictOpt {
59
+ params?: string[];
60
+ eventTime?: "Before";
61
+ }
32
62
 
33
63
  /**
34
64
  *
@@ -36,7 +66,7 @@ export declare function CacheEvict(cacheName: string, eventTime?: eventTimes): (
36
66
  export declare type eventTimes = "Before" | "After";
37
67
 
38
68
  /**
39
- * get instances of cacheStore
69
+ * get instances of storeCache
40
70
  *
41
71
  * @export
42
72
  * @param {Application} app
package/dist/index.js CHANGED
@@ -1,52 +1,31 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2022-05-27 11:35:38
3
+ * @Date: 2023-02-19 01:22:36
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
7
7
  */
8
8
  'use strict';
9
9
 
10
- Object.defineProperty(exports, '__esModule', { value: true });
11
-
12
- var helper = require('koatty_lib');
10
+ var koatty_lib = require('koatty_lib');
13
11
  var koatty_logger = require('koatty_logger');
14
12
  var koatty_store = require('koatty_store');
15
13
  var koatty_container = require('koatty_container');
16
14
 
17
- function _interopNamespace(e) {
18
- if (e && e.__esModule) return e;
19
- var n = Object.create(null);
20
- if (e) {
21
- Object.keys(e).forEach(function (k) {
22
- if (k !== 'default') {
23
- var d = Object.getOwnPropertyDescriptor(e, k);
24
- Object.defineProperty(n, k, d.get ? d : {
25
- enumerable: true,
26
- get: function () { return e[k]; }
27
- });
28
- }
29
- });
30
- }
31
- n["default"] = e;
32
- return Object.freeze(n);
33
- }
34
-
35
- var helper__namespace = /*#__PURE__*/_interopNamespace(helper);
36
-
37
15
  /*
38
16
  * @Author: richen
39
17
  * @Date: 2020-07-06 19:53:43
40
- * @LastEditTime: 2021-12-02 16:20:52
18
+ * @LastEditTime: 2023-02-19 01:16:52
41
19
  * @Description:
42
20
  * @Copyright (c) - <richenlin(at)gmail.com>
43
21
  */
44
- // cacheStore
45
- const cacheStore = {
22
+ const PreKey = "k";
23
+ // storeCache
24
+ const storeCache = {
46
25
  store: null
47
26
  };
48
27
  /**
49
- * get instances of cacheStore
28
+ * get instances of storeCache
50
29
  *
51
30
  * @export
52
31
  * @param {Application} app
@@ -54,18 +33,19 @@ const cacheStore = {
54
33
  */
55
34
  async function GetCacheStore(app) {
56
35
  var _a;
57
- if (cacheStore.store && cacheStore.store.getConnection) {
58
- return cacheStore.store;
36
+ if (storeCache.store && storeCache.store.getConnection) {
37
+ return storeCache.store;
59
38
  }
60
39
  const opt = (_a = app.config("CacheStore", "db")) !== null && _a !== void 0 ? _a : {};
61
- if (helper__namespace.isEmpty(opt)) {
40
+ if (koatty_lib.Helper.isEmpty(opt)) {
62
41
  koatty_logger.DefaultLogger.Warn(`Missing CacheStore server configuration. Please write a configuration item with the key name 'CacheStore' in the db.ts file.`);
63
42
  }
64
- cacheStore.store = koatty_store.Store.getInstance(opt);
65
- if (!helper__namespace.isFunction(cacheStore.store.getConnection)) {
43
+ storeCache.store = koatty_store.CacheStore.getInstance(opt);
44
+ if (!koatty_lib.Helper.isFunction(storeCache.store.getConnection)) {
66
45
  throw Error(`CacheStore connection failed. `);
67
46
  }
68
- return cacheStore.store;
47
+ await storeCache.store.client.getConnection();
48
+ return storeCache.store;
69
49
  }
70
50
  /**
71
51
  * initiation CacheStore connection and client.
@@ -84,18 +64,27 @@ async function InitCacheStore() {
84
64
  *
85
65
  * @export
86
66
  * @param {string} cacheName cache name
87
- * @param {number} [timeout=3600] cache timeout
67
+ * @param {CacheAbleOpt} [opt] cache options
68
+ * e.g:
69
+ * {
70
+ * params: ["id"],
71
+ * timeout: 30
72
+ * }
73
+ * Use the 'id' parameters of the method as cache subkeys, the cache expiration time 30s
88
74
  * @returns {MethodDecorator}
89
75
  */
90
- function CacheAble(cacheName, timeout = 3600) {
76
+ function CacheAble(cacheName, opt = {
77
+ params: [],
78
+ timeout: 3600,
79
+ }) {
91
80
  return (target, methodName, descriptor) => {
92
81
  const componentType = koatty_container.IOCContainer.getType(target);
93
82
  if (componentType !== "SERVICE" && componentType !== "COMPONENT") {
94
83
  throw Error("This decorator only used in the service、component class.");
95
84
  }
96
- let identifier = koatty_container.IOCContainer.getIdentifier(target);
97
- identifier = identifier || (target.constructor ? (target.constructor.name || "") : "");
98
85
  const { value, configurable, enumerable } = descriptor;
86
+ // 获取定义的参数位置
87
+ const paramIndexes = getParamIndex(opt.params, getArgs(value));
99
88
  descriptor = {
100
89
  configurable,
101
90
  enumerable,
@@ -109,26 +98,35 @@ function CacheAble(cacheName, timeout = 3600) {
109
98
  });
110
99
  if (cacheFlag) {
111
100
  // tslint:disable-next-line: one-variable-per-declaration
112
- let key = "", res;
101
+ let key = PreKey;
113
102
  if (props && props.length > 0) {
114
- key = `${identifier}:${methodName}:${helper__namespace.murmurHash(JSON.stringify(props))}`;
103
+ for (const item of paramIndexes) {
104
+ if (props[item] !== undefined) {
105
+ const value = koatty_lib.Helper.toString(props[item]);
106
+ key += `:${value}`;
107
+ }
108
+ }
109
+ // 防止key超长
110
+ if (key.length > 32) {
111
+ key = koatty_lib.Helper.murmurHash(key);
112
+ }
115
113
  }
116
- else {
117
- key = `${identifier}:${methodName}`;
118
- }
119
- res = await store.hget(cacheName, key).catch(() => null);
120
- if (!helper__namespace.isEmpty(res)) {
114
+ let res = await store.get(`${cacheName}:${key}`).catch(() => null);
115
+ if (!koatty_lib.Helper.isEmpty(res)) {
121
116
  return JSON.parse(res);
122
117
  }
123
118
  // tslint:disable-next-line: no-invalid-this
124
119
  res = await value.apply(this, props);
125
120
  // prevent cache penetration
126
- if (helper__namespace.isEmpty(res)) {
121
+ if (koatty_lib.Helper.isEmpty(res)) {
127
122
  res = "";
128
- timeout = 60;
123
+ opt.timeout = 5;
124
+ }
125
+ if (!opt.timeout) {
126
+ opt.timeout = 3600;
129
127
  }
130
128
  // async set store
131
- store.hset(cacheName, key, JSON.stringify(res), timeout).catch(() => null);
129
+ store.set(`${cacheName}:${key}`, JSON.stringify(res), opt.timeout).catch(() => null);
132
130
  return res;
133
131
  }
134
132
  else {
@@ -147,17 +145,26 @@ function CacheAble(cacheName, timeout = 3600) {
147
145
  *
148
146
  * @export
149
147
  * @param {string} cacheName cacheName cache name
150
- * @param {eventTimes} [eventTime="Before"]
148
+ * @param {CacheEvictOpt} [opt] cache options
149
+ * e.g:
150
+ * {
151
+ * params: ["id"],
152
+ * eventTime: "Before"
153
+ * }
154
+ * Use the 'id' parameters of the method as cache subkeys, and clear the cache before the method executed
151
155
  * @returns
152
156
  */
153
- function CacheEvict(cacheName, eventTime = "Before") {
157
+ function CacheEvict(cacheName, opt = {
158
+ eventTime: "Before",
159
+ }) {
154
160
  return (target, methodName, descriptor) => {
155
161
  const componentType = koatty_container.IOCContainer.getType(target);
156
162
  if (componentType !== "SERVICE" && componentType !== "COMPONENT") {
157
163
  throw Error("This decorator only used in the service、component class.");
158
164
  }
159
- koatty_container.IOCContainer.getIdentifier(target);
160
165
  const { value, configurable, enumerable } = descriptor;
166
+ // 获取定义的参数位置
167
+ const paramIndexes = getParamIndex(opt.params, getArgs(value));
161
168
  descriptor = {
162
169
  configurable,
163
170
  enumerable,
@@ -170,15 +177,28 @@ function CacheEvict(cacheName, eventTime = "Before") {
170
177
  return null;
171
178
  });
172
179
  if (cacheFlag) {
173
- if (eventTime === "Before") {
174
- await store.del(cacheName).catch(() => null);
180
+ let key = PreKey;
181
+ if (props && props.length > 0) {
182
+ for (const item of paramIndexes) {
183
+ if (props[item] !== undefined) {
184
+ const value = koatty_lib.Helper.toString(props[item]);
185
+ key += `:${value}`;
186
+ }
187
+ }
188
+ // 防止key超长
189
+ if (key.length > 32) {
190
+ key = koatty_lib.Helper.murmurHash(key);
191
+ }
192
+ }
193
+ if (opt.eventTime === "Before") {
194
+ await store.del(`${cacheName}:${key}`).catch(() => null);
175
195
  // tslint:disable-next-line: no-invalid-this
176
196
  return value.apply(this, props);
177
197
  }
178
198
  else {
179
199
  // tslint:disable-next-line: no-invalid-this
180
200
  const res = await value.apply(this, props);
181
- store.del(cacheName).catch(() => null);
201
+ store.del(`${cacheName}:${key}`).catch(() => null);
182
202
  return res;
183
203
  }
184
204
  }
@@ -192,6 +212,41 @@ function CacheEvict(cacheName, eventTime = "Before") {
192
212
  InitCacheStore();
193
213
  return descriptor;
194
214
  };
215
+ }
216
+ /**
217
+ * @description:
218
+ * @param {*} func
219
+ * @return {*}
220
+ */
221
+ function getArgs(func) {
222
+ // 首先匹配函数括弧里的参数
223
+ const args = func.toString().match(/.*?\(([^)]*)\)/);
224
+ if (args.length > 1) {
225
+ // 分解参数成数组
226
+ return args[1].split(",").map(function (a) {
227
+ // 去空格和内联注释
228
+ return a.replace(/\/\*.*\*\//, "").trim();
229
+ }).filter(function (ae) {
230
+ // 确保没有undefineds
231
+ return ae;
232
+ });
233
+ }
234
+ return [];
235
+ }
236
+ /**
237
+ * @description:
238
+ * @param {string} params
239
+ * @param {string} args
240
+ * @return {*}
241
+ */
242
+ function getParamIndex(params, args) {
243
+ const res = [];
244
+ for (let i = 0; i < params.length; i++) {
245
+ if (params.includes(params[i])) {
246
+ res.push(i);
247
+ }
248
+ }
249
+ return res;
195
250
  }
196
251
 
197
252
  exports.CacheAble = CacheAble;
package/dist/index.mjs CHANGED
@@ -1,28 +1,29 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2022-05-27 11:35:38
3
+ * @Date: 2023-02-19 01:22:36
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
7
7
  */
8
- import * as helper from 'koatty_lib';
8
+ import { Helper } from 'koatty_lib';
9
9
  import { DefaultLogger } from 'koatty_logger';
10
- import { Store } from 'koatty_store';
10
+ import { CacheStore } from 'koatty_store';
11
11
  import { IOCContainer } from 'koatty_container';
12
12
 
13
13
  /*
14
14
  * @Author: richen
15
15
  * @Date: 2020-07-06 19:53:43
16
- * @LastEditTime: 2021-12-02 16:20:52
16
+ * @LastEditTime: 2023-02-19 01:16:52
17
17
  * @Description:
18
18
  * @Copyright (c) - <richenlin(at)gmail.com>
19
19
  */
20
- // cacheStore
21
- const cacheStore = {
20
+ const PreKey = "k";
21
+ // storeCache
22
+ const storeCache = {
22
23
  store: null
23
24
  };
24
25
  /**
25
- * get instances of cacheStore
26
+ * get instances of storeCache
26
27
  *
27
28
  * @export
28
29
  * @param {Application} app
@@ -30,18 +31,19 @@ const cacheStore = {
30
31
  */
31
32
  async function GetCacheStore(app) {
32
33
  var _a;
33
- if (cacheStore.store && cacheStore.store.getConnection) {
34
- return cacheStore.store;
34
+ if (storeCache.store && storeCache.store.getConnection) {
35
+ return storeCache.store;
35
36
  }
36
37
  const opt = (_a = app.config("CacheStore", "db")) !== null && _a !== void 0 ? _a : {};
37
- if (helper.isEmpty(opt)) {
38
+ if (Helper.isEmpty(opt)) {
38
39
  DefaultLogger.Warn(`Missing CacheStore server configuration. Please write a configuration item with the key name 'CacheStore' in the db.ts file.`);
39
40
  }
40
- cacheStore.store = Store.getInstance(opt);
41
- if (!helper.isFunction(cacheStore.store.getConnection)) {
41
+ storeCache.store = CacheStore.getInstance(opt);
42
+ if (!Helper.isFunction(storeCache.store.getConnection)) {
42
43
  throw Error(`CacheStore connection failed. `);
43
44
  }
44
- return cacheStore.store;
45
+ await storeCache.store.client.getConnection();
46
+ return storeCache.store;
45
47
  }
46
48
  /**
47
49
  * initiation CacheStore connection and client.
@@ -60,18 +62,27 @@ async function InitCacheStore() {
60
62
  *
61
63
  * @export
62
64
  * @param {string} cacheName cache name
63
- * @param {number} [timeout=3600] cache timeout
65
+ * @param {CacheAbleOpt} [opt] cache options
66
+ * e.g:
67
+ * {
68
+ * params: ["id"],
69
+ * timeout: 30
70
+ * }
71
+ * Use the 'id' parameters of the method as cache subkeys, the cache expiration time 30s
64
72
  * @returns {MethodDecorator}
65
73
  */
66
- function CacheAble(cacheName, timeout = 3600) {
74
+ function CacheAble(cacheName, opt = {
75
+ params: [],
76
+ timeout: 3600,
77
+ }) {
67
78
  return (target, methodName, descriptor) => {
68
79
  const componentType = IOCContainer.getType(target);
69
80
  if (componentType !== "SERVICE" && componentType !== "COMPONENT") {
70
81
  throw Error("This decorator only used in the service、component class.");
71
82
  }
72
- let identifier = IOCContainer.getIdentifier(target);
73
- identifier = identifier || (target.constructor ? (target.constructor.name || "") : "");
74
83
  const { value, configurable, enumerable } = descriptor;
84
+ // 获取定义的参数位置
85
+ const paramIndexes = getParamIndex(opt.params, getArgs(value));
75
86
  descriptor = {
76
87
  configurable,
77
88
  enumerable,
@@ -85,26 +96,35 @@ function CacheAble(cacheName, timeout = 3600) {
85
96
  });
86
97
  if (cacheFlag) {
87
98
  // tslint:disable-next-line: one-variable-per-declaration
88
- let key = "", res;
99
+ let key = PreKey;
89
100
  if (props && props.length > 0) {
90
- key = `${identifier}:${methodName}:${helper.murmurHash(JSON.stringify(props))}`;
101
+ for (const item of paramIndexes) {
102
+ if (props[item] !== undefined) {
103
+ const value = Helper.toString(props[item]);
104
+ key += `:${value}`;
105
+ }
106
+ }
107
+ // 防止key超长
108
+ if (key.length > 32) {
109
+ key = Helper.murmurHash(key);
110
+ }
91
111
  }
92
- else {
93
- key = `${identifier}:${methodName}`;
94
- }
95
- res = await store.hget(cacheName, key).catch(() => null);
96
- if (!helper.isEmpty(res)) {
112
+ let res = await store.get(`${cacheName}:${key}`).catch(() => null);
113
+ if (!Helper.isEmpty(res)) {
97
114
  return JSON.parse(res);
98
115
  }
99
116
  // tslint:disable-next-line: no-invalid-this
100
117
  res = await value.apply(this, props);
101
118
  // prevent cache penetration
102
- if (helper.isEmpty(res)) {
119
+ if (Helper.isEmpty(res)) {
103
120
  res = "";
104
- timeout = 60;
121
+ opt.timeout = 5;
122
+ }
123
+ if (!opt.timeout) {
124
+ opt.timeout = 3600;
105
125
  }
106
126
  // async set store
107
- store.hset(cacheName, key, JSON.stringify(res), timeout).catch(() => null);
127
+ store.set(`${cacheName}:${key}`, JSON.stringify(res), opt.timeout).catch(() => null);
108
128
  return res;
109
129
  }
110
130
  else {
@@ -123,17 +143,26 @@ function CacheAble(cacheName, timeout = 3600) {
123
143
  *
124
144
  * @export
125
145
  * @param {string} cacheName cacheName cache name
126
- * @param {eventTimes} [eventTime="Before"]
146
+ * @param {CacheEvictOpt} [opt] cache options
147
+ * e.g:
148
+ * {
149
+ * params: ["id"],
150
+ * eventTime: "Before"
151
+ * }
152
+ * Use the 'id' parameters of the method as cache subkeys, and clear the cache before the method executed
127
153
  * @returns
128
154
  */
129
- function CacheEvict(cacheName, eventTime = "Before") {
155
+ function CacheEvict(cacheName, opt = {
156
+ eventTime: "Before",
157
+ }) {
130
158
  return (target, methodName, descriptor) => {
131
159
  const componentType = IOCContainer.getType(target);
132
160
  if (componentType !== "SERVICE" && componentType !== "COMPONENT") {
133
161
  throw Error("This decorator only used in the service、component class.");
134
162
  }
135
- IOCContainer.getIdentifier(target);
136
163
  const { value, configurable, enumerable } = descriptor;
164
+ // 获取定义的参数位置
165
+ const paramIndexes = getParamIndex(opt.params, getArgs(value));
137
166
  descriptor = {
138
167
  configurable,
139
168
  enumerable,
@@ -146,15 +175,28 @@ function CacheEvict(cacheName, eventTime = "Before") {
146
175
  return null;
147
176
  });
148
177
  if (cacheFlag) {
149
- if (eventTime === "Before") {
150
- await store.del(cacheName).catch(() => null);
178
+ let key = PreKey;
179
+ if (props && props.length > 0) {
180
+ for (const item of paramIndexes) {
181
+ if (props[item] !== undefined) {
182
+ const value = Helper.toString(props[item]);
183
+ key += `:${value}`;
184
+ }
185
+ }
186
+ // 防止key超长
187
+ if (key.length > 32) {
188
+ key = Helper.murmurHash(key);
189
+ }
190
+ }
191
+ if (opt.eventTime === "Before") {
192
+ await store.del(`${cacheName}:${key}`).catch(() => null);
151
193
  // tslint:disable-next-line: no-invalid-this
152
194
  return value.apply(this, props);
153
195
  }
154
196
  else {
155
197
  // tslint:disable-next-line: no-invalid-this
156
198
  const res = await value.apply(this, props);
157
- store.del(cacheName).catch(() => null);
199
+ store.del(`${cacheName}:${key}`).catch(() => null);
158
200
  return res;
159
201
  }
160
202
  }
@@ -168,6 +210,41 @@ function CacheEvict(cacheName, eventTime = "Before") {
168
210
  InitCacheStore();
169
211
  return descriptor;
170
212
  };
213
+ }
214
+ /**
215
+ * @description:
216
+ * @param {*} func
217
+ * @return {*}
218
+ */
219
+ function getArgs(func) {
220
+ // 首先匹配函数括弧里的参数
221
+ const args = func.toString().match(/.*?\(([^)]*)\)/);
222
+ if (args.length > 1) {
223
+ // 分解参数成数组
224
+ return args[1].split(",").map(function (a) {
225
+ // 去空格和内联注释
226
+ return a.replace(/\/\*.*\*\//, "").trim();
227
+ }).filter(function (ae) {
228
+ // 确保没有undefineds
229
+ return ae;
230
+ });
231
+ }
232
+ return [];
233
+ }
234
+ /**
235
+ * @description:
236
+ * @param {string} params
237
+ * @param {string} args
238
+ * @return {*}
239
+ */
240
+ function getParamIndex(params, args) {
241
+ const res = [];
242
+ for (let i = 0; i < params.length; i++) {
243
+ if (params.includes(params[i])) {
244
+ res.push(i);
245
+ }
246
+ }
247
+ return res;
171
248
  }
172
249
 
173
250
  export { CacheAble, CacheEvict, GetCacheStore };
package/dist/package.json CHANGED
@@ -1,89 +1,92 @@
1
1
  {
2
- "name": "koatty_cacheable",
3
- "version": "1.3.7",
4
- "description": "Cacheable for koatty.",
5
- "scripts": {
6
- "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
7
- "build:cp": "node scripts/postBuild && copyfiles package.json LICENSE README.md dist/",
8
- "build:js": "del-cli --force dist && npx rollup -c .rollup.config.js",
9
- "build:doc": "del-cli --force docs/api && npx api-documenter markdown --input temp --output docs/api",
10
- "build:dts": "del-cli --force temp && npx tsc && npx api-extractor run --local --verbose",
11
- "eslint": "eslint --ext .ts,.js ./",
12
- "prepublishOnly": "npm test && npm run build",
13
- "prerelease": "npm test && npm run build",
14
- "release": "standard-version",
15
- "test": "npm run eslint && jest --passWithNoTests"
16
- },
17
- "main": "./dist/index.js",
18
- "exports": {
19
- "require": "./dist/index.js",
20
- "import": "./dist/index.mjs"
21
- },
22
- "repository": {
23
- "type": "git",
24
- "url": "git+https://github.com/thinkkoa/koatty_cacheable.git"
25
- },
26
- "keywords": [
27
- "cache",
28
- "store",
29
- "koatty",
30
- "thinkkoa"
31
- ],
32
- "engines": {
33
- "node": ">10.0.0"
34
- },
35
- "author": {
36
- "name": "richenlin",
37
- "email": "richenlin@gmail.com"
38
- },
39
- "license": "BSD-3-Clause",
40
- "bugs": {
41
- "url": "https://github.com/thinkkoa/koatty_cacheable/issues"
42
- },
43
- "homepage": "https://github.com/thinkkoa/koatty_cacheable",
44
- "maintainers": [
45
- {
46
- "name": "richenlin",
47
- "email": "richenlin@gmail.com"
48
- }
49
- ],
50
- "devDependencies": {
51
- "@commitlint/cli": "^17.x.x",
52
- "@commitlint/config-conventional": "^17.x.x",
53
- "@microsoft/api-documenter": "^7.x.x",
54
- "@microsoft/api-extractor": "^7.x.x",
55
- "@rollup/plugin-json": "^4.x.x",
56
- "@types/jest": "^27.x.x",
57
- "@types/koa": "^2.x.x",
58
- "@types/node": "^16.x.x",
59
- "@typescript-eslint/eslint-plugin": "^5.x.x",
60
- "@typescript-eslint/parser": "^5.x.x",
61
- "conventional-changelog-cli": "^2.x.x",
62
- "copyfiles": "^2.x.x",
63
- "del-cli": "^4.x.x",
64
- "eslint": "^8.x.x",
65
- "eslint-plugin-jest": "^26.x.x",
66
- "husky": "^4.x.x",
67
- "jest": "^28.x.x",
68
- "jest-html-reporters": "^3.x.x",
69
- "rollup": "^2.x.x",
70
- "rollup-plugin-typescript2": "^0.x.x",
71
- "standard-version": "^9.x.x",
72
- "ts-jest": "^28.x.x",
73
- "ts-node": "^10.x.x",
74
- "typescript": "^4.x.x"
75
- },
76
- "dependencies": {
77
- "koatty_container": "^1.x.x",
78
- "koatty_lib": "^1.x.x",
79
- "koatty_logger": "^1.x.x",
80
- "koatty_store": "^1.x.x",
81
- "tslib": "^2.4.0"
82
- },
83
- "peerDependencies": {
84
- "koatty_container": "^1.x.x",
85
- "koatty_lib": "^1.x.x",
86
- "koatty_logger": "^1.x.x",
87
- "koatty_store": "^1.x.x"
2
+ "name": "koatty_cacheable",
3
+ "version": "1.4.0",
4
+ "description": "Cacheable for koatty.",
5
+ "scripts": {
6
+ "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
7
+ "build:cp": "node scripts/postBuild && copyfiles package.json LICENSE README.md dist/",
8
+ "build:js": "del-cli --force dist && npx rollup --bundleConfigAsCjs -c .rollup.config.js",
9
+ "build:doc": "del-cli --force docs/api && npx api-documenter markdown --input temp --output docs/api",
10
+ "build:dts": "del-cli --force temp && npx tsc && npx api-extractor run --local --verbose",
11
+ "eslint": "eslint --ext .ts,.js ./",
12
+ "prepublishOnly": "npm test && npm run build",
13
+ "prerelease": "npm test && npm run build",
14
+ "pub": "git push --follow-tags origin && npm publish",
15
+ "release": "standard-version",
16
+ "release:pre": "npm run release -- --prerelease",
17
+ "release:major": "npm run release -- --release-as major",
18
+ "release:minor": "npm run release -- --release-as minor",
19
+ "test": "npm run eslint && jest --passWithNoTests"
20
+ },
21
+ "main": "./dist/index.js",
22
+ "exports": {
23
+ "require": "./dist/index.js",
24
+ "import": "./dist/index.mjs"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/thinkkoa/koatty_cacheable.git"
29
+ },
30
+ "keywords": [
31
+ "cache",
32
+ "store",
33
+ "koatty",
34
+ "thinkkoa"
35
+ ],
36
+ "engines": {
37
+ "node": ">10.0.0"
38
+ },
39
+ "author": {
40
+ "name": "richenlin",
41
+ "email": "richenlin@gmail.com"
42
+ },
43
+ "license": "BSD-3-Clause",
44
+ "bugs": {
45
+ "url": "https://github.com/thinkkoa/koatty_cacheable/issues"
46
+ },
47
+ "homepage": "https://github.com/thinkkoa/koatty_cacheable",
48
+ "maintainers": [
49
+ {
50
+ "name": "richenlin",
51
+ "email": "richenlin@gmail.com"
88
52
  }
53
+ ],
54
+ "devDependencies": {
55
+ "@commitlint/cli": "^17.x.x",
56
+ "@commitlint/config-conventional": "^17.x.x",
57
+ "@microsoft/api-documenter": "^7.x.x",
58
+ "@microsoft/api-extractor": "^7.x.x",
59
+ "@rollup/plugin-json": "^6.x.x",
60
+ "@types/jest": "^29.x.x",
61
+ "@types/koa": "^2.x.x",
62
+ "@types/node": "^18.x.x",
63
+ "@typescript-eslint/eslint-plugin": "^5.x.x",
64
+ "@typescript-eslint/parser": "^5.x.x",
65
+ "conventional-changelog-cli": "^2.x.x",
66
+ "copyfiles": "^2.x.x",
67
+ "del-cli": "^4.x.x",
68
+ "eslint": "^8.x.x",
69
+ "eslint-plugin-jest": "^27.x.x",
70
+ "husky": "^4.x.x",
71
+ "jest": "^29.x.x",
72
+ "jest-html-reporters": "^3.x.x",
73
+ "rollup": "^3.x.x",
74
+ "rollup-plugin-typescript2": "^0.x.x",
75
+ "standard-version": "^9.x.x",
76
+ "ts-jest": "^29.x.x",
77
+ "ts-node": "^10.x.x",
78
+ "typescript": "^4.x.x"
79
+ },
80
+ "dependencies": {
81
+ "koatty_container": "^1.x.x",
82
+ "koatty_lib": "^1.x.x",
83
+ "koatty_logger": "^2.x.x",
84
+ "koatty_store": "^1.x.x"
85
+ },
86
+ "peerDependencies": {
87
+ "koatty_container": "^1.x.x",
88
+ "koatty_lib": "^1.x.x",
89
+ "koatty_logger": "^2.x.x",
90
+ "koatty_store": "^1.x.x"
91
+ }
89
92
  }
package/package.json CHANGED
@@ -1,89 +1,92 @@
1
1
  {
2
- "name": "koatty_cacheable",
3
- "version": "1.3.7",
4
- "description": "Cacheable for koatty.",
5
- "scripts": {
6
- "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
7
- "build:cp": "node scripts/postBuild && copyfiles package.json LICENSE README.md dist/",
8
- "build:js": "del-cli --force dist && npx rollup -c .rollup.config.js",
9
- "build:doc": "del-cli --force docs/api && npx api-documenter markdown --input temp --output docs/api",
10
- "build:dts": "del-cli --force temp && npx tsc && npx api-extractor run --local --verbose",
11
- "eslint": "eslint --ext .ts,.js ./",
12
- "prepublishOnly": "npm test && npm run build",
13
- "prerelease": "npm test && npm run build",
14
- "release": "standard-version",
15
- "test": "npm run eslint && jest --passWithNoTests"
16
- },
17
- "main": "./dist/index.js",
18
- "exports": {
19
- "require": "./dist/index.js",
20
- "import": "./dist/index.mjs"
21
- },
22
- "repository": {
23
- "type": "git",
24
- "url": "git+https://github.com/thinkkoa/koatty_cacheable.git"
25
- },
26
- "keywords": [
27
- "cache",
28
- "store",
29
- "koatty",
30
- "thinkkoa"
31
- ],
32
- "engines": {
33
- "node": ">10.0.0"
34
- },
35
- "author": {
36
- "name": "richenlin",
37
- "email": "richenlin@gmail.com"
38
- },
39
- "license": "BSD-3-Clause",
40
- "bugs": {
41
- "url": "https://github.com/thinkkoa/koatty_cacheable/issues"
42
- },
43
- "homepage": "https://github.com/thinkkoa/koatty_cacheable",
44
- "maintainers": [
45
- {
46
- "name": "richenlin",
47
- "email": "richenlin@gmail.com"
48
- }
49
- ],
50
- "devDependencies": {
51
- "@commitlint/cli": "^17.x.x",
52
- "@commitlint/config-conventional": "^17.x.x",
53
- "@microsoft/api-documenter": "^7.x.x",
54
- "@microsoft/api-extractor": "^7.x.x",
55
- "@rollup/plugin-json": "^4.x.x",
56
- "@types/jest": "^27.x.x",
57
- "@types/koa": "^2.x.x",
58
- "@types/node": "^16.x.x",
59
- "@typescript-eslint/eslint-plugin": "^5.x.x",
60
- "@typescript-eslint/parser": "^5.x.x",
61
- "conventional-changelog-cli": "^2.x.x",
62
- "copyfiles": "^2.x.x",
63
- "del-cli": "^4.x.x",
64
- "eslint": "^8.x.x",
65
- "eslint-plugin-jest": "^26.x.x",
66
- "husky": "^4.x.x",
67
- "jest": "^28.x.x",
68
- "jest-html-reporters": "^3.x.x",
69
- "rollup": "^2.x.x",
70
- "rollup-plugin-typescript2": "^0.x.x",
71
- "standard-version": "^9.x.x",
72
- "ts-jest": "^28.x.x",
73
- "ts-node": "^10.x.x",
74
- "typescript": "^4.x.x"
75
- },
76
- "dependencies": {
77
- "koatty_container": "^1.x.x",
78
- "koatty_lib": "^1.x.x",
79
- "koatty_logger": "^1.x.x",
80
- "koatty_store": "^1.x.x",
81
- "tslib": "^2.4.0"
82
- },
83
- "peerDependencies": {
84
- "koatty_container": "^1.x.x",
85
- "koatty_lib": "^1.x.x",
86
- "koatty_logger": "^1.x.x",
87
- "koatty_store": "^1.x.x"
2
+ "name": "koatty_cacheable",
3
+ "version": "1.4.0",
4
+ "description": "Cacheable for koatty.",
5
+ "scripts": {
6
+ "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
7
+ "build:cp": "node scripts/postBuild && copyfiles package.json LICENSE README.md dist/",
8
+ "build:js": "del-cli --force dist && npx rollup --bundleConfigAsCjs -c .rollup.config.js",
9
+ "build:doc": "del-cli --force docs/api && npx api-documenter markdown --input temp --output docs/api",
10
+ "build:dts": "del-cli --force temp && npx tsc && npx api-extractor run --local --verbose",
11
+ "eslint": "eslint --ext .ts,.js ./",
12
+ "prepublishOnly": "npm test && npm run build",
13
+ "prerelease": "npm test && npm run build",
14
+ "pub": "git push --follow-tags origin && npm publish",
15
+ "release": "standard-version",
16
+ "release:pre": "npm run release -- --prerelease",
17
+ "release:major": "npm run release -- --release-as major",
18
+ "release:minor": "npm run release -- --release-as minor",
19
+ "test": "npm run eslint && jest --passWithNoTests"
20
+ },
21
+ "main": "./dist/index.js",
22
+ "exports": {
23
+ "require": "./dist/index.js",
24
+ "import": "./dist/index.mjs"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/thinkkoa/koatty_cacheable.git"
29
+ },
30
+ "keywords": [
31
+ "cache",
32
+ "store",
33
+ "koatty",
34
+ "thinkkoa"
35
+ ],
36
+ "engines": {
37
+ "node": ">10.0.0"
38
+ },
39
+ "author": {
40
+ "name": "richenlin",
41
+ "email": "richenlin@gmail.com"
42
+ },
43
+ "license": "BSD-3-Clause",
44
+ "bugs": {
45
+ "url": "https://github.com/thinkkoa/koatty_cacheable/issues"
46
+ },
47
+ "homepage": "https://github.com/thinkkoa/koatty_cacheable",
48
+ "maintainers": [
49
+ {
50
+ "name": "richenlin",
51
+ "email": "richenlin@gmail.com"
88
52
  }
53
+ ],
54
+ "devDependencies": {
55
+ "@commitlint/cli": "^17.x.x",
56
+ "@commitlint/config-conventional": "^17.x.x",
57
+ "@microsoft/api-documenter": "^7.x.x",
58
+ "@microsoft/api-extractor": "^7.x.x",
59
+ "@rollup/plugin-json": "^6.x.x",
60
+ "@types/jest": "^29.x.x",
61
+ "@types/koa": "^2.x.x",
62
+ "@types/node": "^18.x.x",
63
+ "@typescript-eslint/eslint-plugin": "^5.x.x",
64
+ "@typescript-eslint/parser": "^5.x.x",
65
+ "conventional-changelog-cli": "^2.x.x",
66
+ "copyfiles": "^2.x.x",
67
+ "del-cli": "^4.x.x",
68
+ "eslint": "^8.x.x",
69
+ "eslint-plugin-jest": "^27.x.x",
70
+ "husky": "^4.x.x",
71
+ "jest": "^29.x.x",
72
+ "jest-html-reporters": "^3.x.x",
73
+ "rollup": "^3.x.x",
74
+ "rollup-plugin-typescript2": "^0.x.x",
75
+ "standard-version": "^9.x.x",
76
+ "ts-jest": "^29.x.x",
77
+ "ts-node": "^10.x.x",
78
+ "typescript": "^4.x.x"
79
+ },
80
+ "dependencies": {
81
+ "koatty_container": "^1.x.x",
82
+ "koatty_lib": "^1.x.x",
83
+ "koatty_logger": "^2.x.x",
84
+ "koatty_store": "^1.x.x"
85
+ },
86
+ "peerDependencies": {
87
+ "koatty_container": "^1.x.x",
88
+ "koatty_lib": "^1.x.x",
89
+ "koatty_logger": "^2.x.x",
90
+ "koatty_store": "^1.x.x"
91
+ }
89
92
  }