@azteam/express 1.2.151 → 1.2.152

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.151",
3
+ "version": "1.2.152",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "@azteam/error": "latest",
28
28
  "@azteam/http-client": "latest",
29
29
  "@azteam/rabbitmq-async": "latest",
30
- "@azteam/redis-async": "latest",
30
+ "@azteam/redis-async": "1.0.48",
31
31
  "@grpc/grpc-js": "1.6.7",
32
32
  "@grpc/proto-loader": "0.6.12",
33
33
  "body-parser": "1.19.0",
@@ -41,6 +41,7 @@
41
41
  "fastest-validator": "1.8.0",
42
42
  "helmet": "3.21.2",
43
43
  "jsonwebtoken": "8.2.1",
44
+ "lodash": "4.17.21",
44
45
  "method-override": "3.0.0",
45
46
  "morgan": "1.10.0",
46
47
  "socket.io": "4.4.1",
package/src/Server.js CHANGED
@@ -241,7 +241,7 @@ class Server {
241
241
  };
242
242
 
243
243
  if (this.redis && this.cache) {
244
- this.redis.set(this.cache.key, resData, this.ttl);
244
+ this.redis.set(this.cache.key, resData, this.cache.ttl);
245
245
  }
246
246
 
247
247
  return this.json(resData);
@@ -1,14 +1,32 @@
1
- export default function(key, ttl = 5) {
1
+ import _ from 'lodash';
2
+
3
+ export default function(key, options = {}) {
4
+ options = {
5
+ ttl: 5,
6
+ limitPage: 5,
7
+ ...options
8
+ };
2
9
  return async function(req, res, next) {
3
10
  const {redis} = req;
4
11
  if (redis) {
12
+ if (options.query) {
13
+ key += _.get(req, options.query);
14
+ }
15
+ if (req.paginate) ;
16
+ {
17
+ if (req.paginate.page <= options.limitPage) {
18
+ key += `page${req.paginate.page}`;
19
+ } else {
20
+ return next();
21
+ }
22
+ }
5
23
  const cacheData = await redis.get(key);
6
24
  if (cacheData) {
7
25
  return res.json(cacheData);
8
26
  } else {
9
27
  res.cache = {
10
28
  key,
11
- ttl
29
+ ttl: options.ttl
12
30
  };
13
31
  }
14
32
  }