@azteam/express 1.2.520 → 1.2.521

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.
@@ -34,7 +34,7 @@ function _default(key) {
34
34
  case 0:
35
35
  redis = req.redis;
36
36
  if (!redis) {
37
- _context.next = 43;
37
+ _context.next = 45;
38
38
  break;
39
39
  }
40
40
  cacheKey = typeof key === 'function' ? key(req) : key;
@@ -75,7 +75,7 @@ function _default(key) {
75
75
  return _context.abrupt("return", res.json(cacheData));
76
76
  case 17:
77
77
  if (!(options.singleFlight && cacheKey)) {
78
- _context.next = 42;
78
+ _context.next = 44;
79
79
  break;
80
80
  }
81
81
  flightKey = "flight:".concat(cacheKey);
@@ -132,7 +132,15 @@ function _default(key) {
132
132
  if (resolveFlight) {
133
133
  resolveFlight(result);
134
134
  }
135
- }; // Intercept res.success để lấy resData trước khi gửi đi
135
+ }; // Lắng nghe sự kiện response kết thúc (finish/close) để dọn dẹp tuyệt đối kể cả khi handler bị crash ngoài ý muốn
136
+ res.once('finish', function () {
137
+ return cleanup(null);
138
+ });
139
+ res.once('close', function () {
140
+ return cleanup(null);
141
+ });
142
+
143
+ // Intercept res.success để lấy resData trước khi gửi đi
136
144
  originalSuccess = res.success.bind(res);
137
145
  originalError = res.error.bind(res);
138
146
  res.success = function () {
@@ -161,14 +169,14 @@ function _default(key) {
161
169
  });
162
170
  return originalError(code, errors);
163
171
  };
164
- case 42:
172
+ case 44:
165
173
  res.cache = {
166
174
  key: cacheKey,
167
175
  ttl: options.ttl
168
176
  };
169
- case 43:
177
+ case 45:
170
178
  return _context.abrupt("return", next());
171
- case 44:
179
+ case 46:
172
180
  case "end":
173
181
  return _context.stop();
174
182
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.520",
3
+ "version": "1.2.521",
4
4
  "license": "MIT",
5
5
  "author": "toda <sp.azsolution.net@gmail.com>",
6
6
  "main": "./lib/index.js",
@@ -88,6 +88,10 @@ export default function (key, opts = {}) {
88
88
  }
89
89
  };
90
90
 
91
+ // Lắng nghe sự kiện response kết thúc (finish/close) để dọn dẹp tuyệt đối kể cả khi handler bị crash ngoài ý muốn
92
+ res.once('finish', () => cleanup(null));
93
+ res.once('close', () => cleanup(null));
94
+
91
95
  // Intercept res.success để lấy resData trước khi gửi đi
92
96
  const originalSuccess = res.success.bind(res);
93
97
  const originalError = res.error.bind(res);