@azteam/express 1.2.152 → 1.2.153

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.152",
3
+ "version": "1.2.153",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -26,8 +26,6 @@
26
26
  "@azteam/crypto": "latest",
27
27
  "@azteam/error": "latest",
28
28
  "@azteam/http-client": "latest",
29
- "@azteam/rabbitmq-async": "latest",
30
- "@azteam/redis-async": "1.0.48",
31
29
  "@grpc/grpc-js": "1.6.7",
32
30
  "@grpc/proto-loader": "0.6.12",
33
31
  "body-parser": "1.19.0",
@@ -1,31 +1,33 @@
1
1
  import _ from 'lodash';
2
+ import qs from 'querystring';
2
3
 
3
4
  export default function(key, options = {}) {
4
5
  options = {
5
- ttl: 5,
6
+ ttl: 300,
6
7
  limitPage: 5,
7
8
  ...options
8
9
  };
9
10
  return async function(req, res, next) {
10
11
  const {redis} = req;
11
12
  if (redis) {
13
+ let cacheKey = key;
14
+
12
15
  if (options.query) {
13
- key += _.get(req, options.query);
16
+ cacheKey += `${cacheKey}:${_.get(req, options.query)}`;
14
17
  }
15
- if (req.paginate) ;
16
- {
17
- if (req.paginate.page <= options.limitPage) {
18
- key += `page${req.paginate.page}`;
18
+ if (req.paginate) {
19
+ if (_.isEmpty(req.query) && req.paginate.page <= options.limitPage) {
20
+ cacheKey = `${cacheKey}:${qs.stringify(req.paginate)}`;
19
21
  } else {
20
22
  return next();
21
23
  }
22
24
  }
23
- const cacheData = await redis.get(key);
25
+ const cacheData = await redis.get(cacheKey);
24
26
  if (cacheData) {
25
27
  return res.json(cacheData);
26
28
  } else {
27
29
  res.cache = {
28
- key,
30
+ key: cacheKey,
29
31
  ttl: options.ttl
30
32
  };
31
33
  }