@modern-js/prod-server 2.9.1-alpha.0 → 2.11.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 +45 -0
- package/dist/cjs/libs/hook-api/index.js +7 -26
- package/dist/cjs/libs/render/index.js +2 -1
- package/dist/cjs/libs/render/ssr.js +7 -5
- package/dist/{js/node/libs/metrics.js → cjs/libs/render/utils.js} +25 -12
- package/dist/cjs/server/index.js +1 -1
- package/dist/cjs/server/modernServer.js +75 -80
- package/dist/esm/libs/hook-api/index.js +9 -37
- package/dist/esm/libs/render/index.js +2 -1
- package/dist/esm/libs/render/ssr.js +6 -4
- package/dist/esm/libs/render/utils.js +12 -0
- package/dist/esm/server/index.js +2 -2
- package/dist/esm/server/modernServer.js +108 -103
- package/dist/esm-node/libs/hook-api/index.js +7 -26
- package/dist/esm-node/libs/render/index.js +2 -1
- package/dist/esm-node/libs/render/ssr.js +7 -7
- package/dist/esm-node/libs/render/utils.js +23 -0
- package/dist/esm-node/server/index.js +1 -1
- package/dist/esm-node/server/modernServer.js +75 -80
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/libs/render/utils.d.ts +5 -0
- package/dist/types/server/index.d.ts +2 -1
- package/dist/types/server/modernServer.d.ts +4 -4
- package/dist/types/type.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +9 -7
- package/dist/js/modern/constants.js +0 -35
- package/dist/js/modern/index.js +0 -18
- package/dist/js/modern/libs/context/context.js +0 -160
- package/dist/js/modern/libs/context/index.js +0 -6
- package/dist/js/modern/libs/hook-api/index.js +0 -134
- package/dist/js/modern/libs/hook-api/route.js +0 -20
- package/dist/js/modern/libs/hook-api/template.js +0 -73
- package/dist/js/modern/libs/loadConfig.js +0 -62
- package/dist/js/modern/libs/logger.js +0 -111
- package/dist/js/modern/libs/metrics.js +0 -11
- package/dist/js/modern/libs/proxy.js +0 -92
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -114
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -254
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +0 -47
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +0 -37
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +0 -91
- package/dist/js/modern/libs/render/cache/index.js +0 -115
- package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -29
- package/dist/js/modern/libs/render/cache/spr.js +0 -248
- package/dist/js/modern/libs/render/cache/type.js +0 -0
- package/dist/js/modern/libs/render/cache/util.js +0 -102
- package/dist/js/modern/libs/render/index.js +0 -86
- package/dist/js/modern/libs/render/measure.js +0 -68
- package/dist/js/modern/libs/render/reader.js +0 -107
- package/dist/js/modern/libs/render/ssr.js +0 -100
- package/dist/js/modern/libs/render/static.js +0 -60
- package/dist/js/modern/libs/render/type.js +0 -9
- package/dist/js/modern/libs/route/index.js +0 -54
- package/dist/js/modern/libs/route/matcher.js +0 -87
- package/dist/js/modern/libs/route/route.js +0 -16
- package/dist/js/modern/libs/serve-file.js +0 -67
- package/dist/js/modern/server/index.js +0 -208
- package/dist/js/modern/server/modern-server-split.js +0 -74
- package/dist/js/modern/server/modern-server.js +0 -554
- package/dist/js/modern/type.js +0 -0
- package/dist/js/modern/utils.js +0 -136
- package/dist/js/modern/worker-server.js +0 -89
- package/dist/js/node/constants.js +0 -62
- package/dist/js/node/index.js +0 -44
- package/dist/js/node/libs/context/context.js +0 -189
- package/dist/js/node/libs/context/index.js +0 -30
- package/dist/js/node/libs/hook-api/index.js +0 -164
- package/dist/js/node/libs/hook-api/route.js +0 -43
- package/dist/js/node/libs/hook-api/template.js +0 -97
- package/dist/js/node/libs/loadConfig.js +0 -91
- package/dist/js/node/libs/logger.js +0 -133
- package/dist/js/node/libs/proxy.js +0 -114
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -115
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -245
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +0 -70
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +0 -60
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +0 -114
- package/dist/js/node/libs/render/cache/index.js +0 -134
- package/dist/js/node/libs/render/cache/page-caches/index.js +0 -55
- package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -58
- package/dist/js/node/libs/render/cache/spr.js +0 -270
- package/dist/js/node/libs/render/cache/type.js +0 -15
- package/dist/js/node/libs/render/cache/util.js +0 -138
- package/dist/js/node/libs/render/index.js +0 -115
- package/dist/js/node/libs/render/measure.js +0 -90
- package/dist/js/node/libs/render/reader.js +0 -140
- package/dist/js/node/libs/render/ssr.js +0 -123
- package/dist/js/node/libs/render/static.js +0 -89
- package/dist/js/node/libs/render/type.js +0 -32
- package/dist/js/node/libs/route/index.js +0 -78
- package/dist/js/node/libs/route/matcher.js +0 -106
- package/dist/js/node/libs/route/route.js +0 -39
- package/dist/js/node/libs/serve-file.js +0 -97
- package/dist/js/node/server/index.js +0 -219
- package/dist/js/node/server/modern-server-split.js +0 -97
- package/dist/js/node/server/modern-server.js +0 -559
- package/dist/js/node/type.js +0 -15
- package/dist/js/node/utils.js +0 -166
- package/dist/js/node/worker-server.js +0 -113
- package/dist/js/treeshaking/constants.js +0 -29
- package/dist/js/treeshaking/index.js +0 -13
- package/dist/js/treeshaking/libs/context/context.js +0 -274
- package/dist/js/treeshaking/libs/context/index.js +0 -5
- package/dist/js/treeshaking/libs/hook-api/index.js +0 -281
- package/dist/js/treeshaking/libs/hook-api/route.js +0 -68
- package/dist/js/treeshaking/libs/hook-api/template.js +0 -127
- package/dist/js/treeshaking/libs/loadConfig.js +0 -82
- package/dist/js/treeshaking/libs/logger.js +0 -205
- package/dist/js/treeshaking/libs/metrics.js +0 -6
- package/dist/js/treeshaking/libs/proxy.js +0 -244
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +0 -291
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +0 -781
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +0 -67
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +0 -45
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +0 -147
- package/dist/js/treeshaking/libs/render/cache/index.js +0 -346
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +0 -154
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +0 -84
- package/dist/js/treeshaking/libs/render/cache/spr.js +0 -492
- package/dist/js/treeshaking/libs/render/cache/type.js +0 -1
- package/dist/js/treeshaking/libs/render/cache/util.js +0 -280
- package/dist/js/treeshaking/libs/render/index.js +0 -234
- package/dist/js/treeshaking/libs/render/measure.js +0 -146
- package/dist/js/treeshaking/libs/render/reader.js +0 -339
- package/dist/js/treeshaking/libs/render/ssr.js +0 -223
- package/dist/js/treeshaking/libs/render/static.js +0 -216
- package/dist/js/treeshaking/libs/render/type.js +0 -7
- package/dist/js/treeshaking/libs/route/index.js +0 -130
- package/dist/js/treeshaking/libs/route/matcher.js +0 -143
- package/dist/js/treeshaking/libs/route/route.js +0 -40
- package/dist/js/treeshaking/libs/serve-file.js +0 -184
- package/dist/js/treeshaking/server/index.js +0 -505
- package/dist/js/treeshaking/server/modern-server-split.js +0 -360
- package/dist/js/treeshaking/server/modern-server.js +0 -1089
- package/dist/js/treeshaking/type.js +0 -1
- package/dist/js/treeshaking/utils.js +0 -147
- package/dist/js/treeshaking/worker-server.js +0 -233
|
@@ -1,492 +0,0 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _asyncToGenerator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _classCallCheck(instance, Constructor) {
|
|
31
|
-
if (!(instance instanceof Constructor)) {
|
|
32
|
-
throw new TypeError("Cannot call a class as a function");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function _defineProperties(target, props) {
|
|
36
|
-
for(var i = 0; i < props.length; i++){
|
|
37
|
-
var descriptor = props[i];
|
|
38
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
39
|
-
descriptor.configurable = true;
|
|
40
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
41
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
45
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
46
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
47
|
-
return Constructor;
|
|
48
|
-
}
|
|
49
|
-
function _defineProperty(obj, key, value) {
|
|
50
|
-
if (key in obj) {
|
|
51
|
-
Object.defineProperty(obj, key, {
|
|
52
|
-
value: value,
|
|
53
|
-
enumerable: true,
|
|
54
|
-
configurable: true,
|
|
55
|
-
writable: true
|
|
56
|
-
});
|
|
57
|
-
} else {
|
|
58
|
-
obj[key] = value;
|
|
59
|
-
}
|
|
60
|
-
return obj;
|
|
61
|
-
}
|
|
62
|
-
var __generator = this && this.__generator || function(thisArg, body) {
|
|
63
|
-
var f, y, t, g, _ = {
|
|
64
|
-
label: 0,
|
|
65
|
-
sent: function() {
|
|
66
|
-
if (t[0] & 1) throw t[1];
|
|
67
|
-
return t[1];
|
|
68
|
-
},
|
|
69
|
-
trys: [],
|
|
70
|
-
ops: []
|
|
71
|
-
};
|
|
72
|
-
return(g = {
|
|
73
|
-
next: verb(0),
|
|
74
|
-
"throw": verb(1),
|
|
75
|
-
"return": verb(2)
|
|
76
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
77
|
-
return this;
|
|
78
|
-
}), g);
|
|
79
|
-
function verb(n) {
|
|
80
|
-
return function(v) {
|
|
81
|
-
return step([
|
|
82
|
-
n,
|
|
83
|
-
v
|
|
84
|
-
]);
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
function step(op) {
|
|
88
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
89
|
-
while(_)try {
|
|
90
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
91
|
-
if (y = 0, t) op = [
|
|
92
|
-
op[0] & 2,
|
|
93
|
-
t.value
|
|
94
|
-
];
|
|
95
|
-
switch(op[0]){
|
|
96
|
-
case 0:
|
|
97
|
-
case 1:
|
|
98
|
-
t = op;
|
|
99
|
-
break;
|
|
100
|
-
case 4:
|
|
101
|
-
_.label++;
|
|
102
|
-
return {
|
|
103
|
-
value: op[1],
|
|
104
|
-
done: false
|
|
105
|
-
};
|
|
106
|
-
case 5:
|
|
107
|
-
_.label++;
|
|
108
|
-
y = op[1];
|
|
109
|
-
op = [
|
|
110
|
-
0
|
|
111
|
-
];
|
|
112
|
-
continue;
|
|
113
|
-
case 7:
|
|
114
|
-
op = _.ops.pop();
|
|
115
|
-
_.trys.pop();
|
|
116
|
-
continue;
|
|
117
|
-
default:
|
|
118
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
119
|
-
_ = 0;
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
123
|
-
_.label = op[1];
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
127
|
-
_.label = t[1];
|
|
128
|
-
t = op;
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
if (t && _.label < t[2]) {
|
|
132
|
-
_.label = t[2];
|
|
133
|
-
_.ops.push(op);
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
if (t[2]) _.ops.pop();
|
|
137
|
-
_.trys.pop();
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
op = body.call(thisArg, _);
|
|
141
|
-
} catch (e) {
|
|
142
|
-
op = [
|
|
143
|
-
6,
|
|
144
|
-
e
|
|
145
|
-
];
|
|
146
|
-
y = 0;
|
|
147
|
-
} finally{
|
|
148
|
-
f = t = 0;
|
|
149
|
-
}
|
|
150
|
-
if (op[0] & 5) throw op[1];
|
|
151
|
-
return {
|
|
152
|
-
value: op[0] ? op[1] : void 0,
|
|
153
|
-
done: true
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
import crypto from "crypto";
|
|
158
|
-
import LRUCache from "lru-cache";
|
|
159
|
-
import { mime } from "@modern-js/utils";
|
|
160
|
-
import { cacheAddition, connectFactor, fname, maybeSync, namespaceHash, valueFactory, withCoalescedInvoke } from "./util";
|
|
161
|
-
import { createPageCaches } from "./page-caches";
|
|
162
|
-
var MAX_CACHE_EACH_REQ = Number(process.env.ROUTE_CACHE_LIMIT) || 10;
|
|
163
|
-
var MAX_SIZE_EACH_CLUSTER = Number(process.env.CLUSTER_CACHE_LIMIT) || 100;
|
|
164
|
-
var BASE_LEVEL = 0;
|
|
165
|
-
var QUERY_LEVEL = 1;
|
|
166
|
-
var HEADER_LEVEL = 2;
|
|
167
|
-
var QUERY_HEADER_LEVEL = 3;
|
|
168
|
-
var CacheManager = /*#__PURE__*/ function() {
|
|
169
|
-
"use strict";
|
|
170
|
-
function CacheManager(cacheOptions) {
|
|
171
|
-
var _this = this;
|
|
172
|
-
_classCallCheck(this, CacheManager);
|
|
173
|
-
_defineProperty(this, "cache", void 0);
|
|
174
|
-
_defineProperty(this, "cacheOptions", void 0);
|
|
175
|
-
_defineProperty(this, "find", function() {
|
|
176
|
-
{
|
|
177
|
-
var _this1 = _this;
|
|
178
|
-
var _obj;
|
|
179
|
-
return(_obj = {}, _defineProperty(_obj, fname(BASE_LEVEL), function(context, cacheKey) {
|
|
180
|
-
return _this1.md5(cacheKey);
|
|
181
|
-
}), _defineProperty(_obj, fname(QUERY_LEVEL), function(context, cacheKey, data) {
|
|
182
|
-
var queryFactor = _this1.queryFactor(context, data);
|
|
183
|
-
if (!queryFactor) {
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
return _this1.md5(connectFactor(cacheKey, queryFactor));
|
|
187
|
-
}), _defineProperty(_obj, fname(HEADER_LEVEL), function(context, cacheKey, data) {
|
|
188
|
-
var headerFactor = _this1.headerFactor(context, data);
|
|
189
|
-
if (!headerFactor) {
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
return _this1.md5(connectFactor(cacheKey, headerFactor));
|
|
193
|
-
}), _defineProperty(_obj, fname(QUERY_HEADER_LEVEL), function(context, cacheKey, data) {
|
|
194
|
-
var queryFactor = _this1.queryFactor(context, data);
|
|
195
|
-
var headerFactor = _this1.headerFactor(context, data);
|
|
196
|
-
if (!queryFactor || !headerFactor) {
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
return _this1.md5(connectFactor(cacheKey, headerFactor, queryFactor));
|
|
200
|
-
}), _obj);
|
|
201
|
-
}
|
|
202
|
-
}());
|
|
203
|
-
this.cacheOptions = cacheOptions;
|
|
204
|
-
this.cache = new LRUCache({
|
|
205
|
-
max: Math.min(MAX_SIZE_EACH_CLUSTER, 600) * 1024 * 1024,
|
|
206
|
-
length: function length(n) {
|
|
207
|
-
var len = n.caches.keys().reduce(function(total, cur) {
|
|
208
|
-
var _n_caches_peek;
|
|
209
|
-
return total + (((_n_caches_peek = n.caches.peek(cur)) === null || _n_caches_peek === void 0 ? void 0 : _n_caches_peek.size) || 0);
|
|
210
|
-
}, 1);
|
|
211
|
-
return len;
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
_createClass(CacheManager, [
|
|
216
|
-
{
|
|
217
|
-
key: "md5",
|
|
218
|
-
value: function md5(content) {
|
|
219
|
-
var md5 = crypto.createHash("md5");
|
|
220
|
-
return md5.update(content).digest("hex");
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
key: "generateRequestKey",
|
|
225
|
-
value: function generateRequestKey(context) {
|
|
226
|
-
var pathname = context.pathname, entry = context.entry;
|
|
227
|
-
return this.md5("".concat(pathname, "_").concat(entry));
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
key: "replaceValue",
|
|
232
|
-
value: function replaceValue(value, matcher) {
|
|
233
|
-
var final = value;
|
|
234
|
-
Object.keys(matcher).some(function(replacer) {
|
|
235
|
-
var reg = new RegExp(matcher[replacer]);
|
|
236
|
-
if (reg.test(value)) {
|
|
237
|
-
final = replacer;
|
|
238
|
-
return true;
|
|
239
|
-
}
|
|
240
|
-
return false;
|
|
241
|
-
});
|
|
242
|
-
return final;
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
key: "factor",
|
|
247
|
-
value: function factor(keys, obj) {
|
|
248
|
-
var matches = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
249
|
-
var _this = this;
|
|
250
|
-
keys.sort();
|
|
251
|
-
var getValue = valueFactory(obj);
|
|
252
|
-
var factorAry = keys.reduce(function(ary, key) {
|
|
253
|
-
var value = getValue(key) || "";
|
|
254
|
-
var matcher = matches[key];
|
|
255
|
-
if (matcher) {
|
|
256
|
-
value = _this.replaceValue(value, matcher);
|
|
257
|
-
}
|
|
258
|
-
return ary.concat([
|
|
259
|
-
key,
|
|
260
|
-
value
|
|
261
|
-
]);
|
|
262
|
-
}, []);
|
|
263
|
-
return factorAry.join(",");
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
key: "queryFactor",
|
|
268
|
-
value: function queryFactor(context, data) {
|
|
269
|
-
var _data_includes, _data_matches;
|
|
270
|
-
var queryKeys = (_data_includes = data.includes) === null || _data_includes === void 0 ? void 0 : _data_includes.query;
|
|
271
|
-
var queryMatches = (_data_matches = data.matches) === null || _data_matches === void 0 ? void 0 : _data_matches.query;
|
|
272
|
-
if (!queryKeys || queryKeys.length === 0) {
|
|
273
|
-
return null;
|
|
274
|
-
}
|
|
275
|
-
var requestQuery = context.query;
|
|
276
|
-
var queryFactor = this.factor(queryKeys, requestQuery, queryMatches);
|
|
277
|
-
return queryFactor;
|
|
278
|
-
}
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
key: "headerFactor",
|
|
282
|
-
value: function headerFactor(context, data) {
|
|
283
|
-
var _data_includes, _data_matches;
|
|
284
|
-
var headerKeys = (_data_includes = data.includes) === null || _data_includes === void 0 ? void 0 : _data_includes.header;
|
|
285
|
-
var headerMatches = (_data_matches = data.matches) === null || _data_matches === void 0 ? void 0 : _data_matches.header;
|
|
286
|
-
if (!headerKeys || headerKeys.length === 0) {
|
|
287
|
-
return null;
|
|
288
|
-
}
|
|
289
|
-
var requestHeader = context.headers;
|
|
290
|
-
var headerFactor = this.factor(headerKeys, requestHeader, headerMatches);
|
|
291
|
-
return headerFactor;
|
|
292
|
-
}
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
key: "best",
|
|
296
|
-
value: function best(context, cacheKey, data) {
|
|
297
|
-
var _this = this;
|
|
298
|
-
return _asyncToGenerator(function() {
|
|
299
|
-
var level, cacheHash;
|
|
300
|
-
return __generator(this, function(_state) {
|
|
301
|
-
level = data.level;
|
|
302
|
-
cacheHash = _this.find[fname(level)](context, cacheKey, data);
|
|
303
|
-
if (!cacheHash) {
|
|
304
|
-
return [
|
|
305
|
-
2,
|
|
306
|
-
null
|
|
307
|
-
];
|
|
308
|
-
}
|
|
309
|
-
return [
|
|
310
|
-
2,
|
|
311
|
-
data.caches.get(cacheHash)
|
|
312
|
-
];
|
|
313
|
-
});
|
|
314
|
-
})();
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
{
|
|
318
|
-
key: "createCacheContent",
|
|
319
|
-
value: function createCacheContent(config, caches) {
|
|
320
|
-
return {
|
|
321
|
-
level: config.level,
|
|
322
|
-
interval: config.interval,
|
|
323
|
-
includes: config.includes || null,
|
|
324
|
-
limit: config.staleLimit,
|
|
325
|
-
matches: config.matches || null,
|
|
326
|
-
caches: caches
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
key: "get",
|
|
332
|
-
value: function get(context) {
|
|
333
|
-
var _this = this;
|
|
334
|
-
return _asyncToGenerator(function() {
|
|
335
|
-
var cacheKey, data, dest, expireTime, limitTime, html, cacheHash, isStale, isGarbage;
|
|
336
|
-
return __generator(this, function(_state) {
|
|
337
|
-
switch(_state.label){
|
|
338
|
-
case 0:
|
|
339
|
-
cacheKey = _this.generateRequestKey(context);
|
|
340
|
-
data = _this.cache.get(cacheKey);
|
|
341
|
-
if (!data) {
|
|
342
|
-
return [
|
|
343
|
-
2,
|
|
344
|
-
null
|
|
345
|
-
];
|
|
346
|
-
}
|
|
347
|
-
return [
|
|
348
|
-
4,
|
|
349
|
-
_this.best(context, cacheKey, data)
|
|
350
|
-
];
|
|
351
|
-
case 1:
|
|
352
|
-
dest = _state.sent();
|
|
353
|
-
if (!dest) {
|
|
354
|
-
return [
|
|
355
|
-
2,
|
|
356
|
-
null
|
|
357
|
-
];
|
|
358
|
-
}
|
|
359
|
-
expireTime = dest.expireTime, limitTime = dest.limitTime, html = dest.html, cacheHash = dest.cacheHash;
|
|
360
|
-
isStale = Date.now() - expireTime > 0;
|
|
361
|
-
isGarbage = limitTime ? Date.now() - limitTime > 0 : false;
|
|
362
|
-
return [
|
|
363
|
-
2,
|
|
364
|
-
{
|
|
365
|
-
content: html || "",
|
|
366
|
-
contentType: mime.contentType("html"),
|
|
367
|
-
isStale: isStale,
|
|
368
|
-
isGarbage: isGarbage,
|
|
369
|
-
hash: cacheHash
|
|
370
|
-
}
|
|
371
|
-
];
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
})();
|
|
375
|
-
}
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
key: "set",
|
|
379
|
-
value: function set(context, html, cacheConfig) {
|
|
380
|
-
var sync = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
|
|
381
|
-
var _this = this;
|
|
382
|
-
return _asyncToGenerator(function() {
|
|
383
|
-
var cacheKey, data, caches, cacheHash, cacheSyncOrAsync, doCache;
|
|
384
|
-
return __generator(this, function(_state) {
|
|
385
|
-
switch(_state.label){
|
|
386
|
-
case 0:
|
|
387
|
-
if (!cacheConfig) {
|
|
388
|
-
return [
|
|
389
|
-
2,
|
|
390
|
-
false
|
|
391
|
-
];
|
|
392
|
-
}
|
|
393
|
-
cacheKey = _this.generateRequestKey(context);
|
|
394
|
-
data = _this.cache.get(cacheKey);
|
|
395
|
-
if (!!data) return [
|
|
396
|
-
3,
|
|
397
|
-
2
|
|
398
|
-
];
|
|
399
|
-
return [
|
|
400
|
-
4,
|
|
401
|
-
createPageCaches(MAX_CACHE_EACH_REQ)
|
|
402
|
-
];
|
|
403
|
-
case 1:
|
|
404
|
-
caches = _state.sent();
|
|
405
|
-
data = _this.createCacheContent(cacheConfig, caches);
|
|
406
|
-
_state.label = 2;
|
|
407
|
-
case 2:
|
|
408
|
-
cacheHash = _this.find[fname(cacheConfig.level)](context, cacheKey, data);
|
|
409
|
-
if (!cacheHash) {
|
|
410
|
-
return [
|
|
411
|
-
2,
|
|
412
|
-
false
|
|
413
|
-
];
|
|
414
|
-
}
|
|
415
|
-
cacheSyncOrAsync = function() {
|
|
416
|
-
var _ref = _asyncToGenerator(function() {
|
|
417
|
-
var next, limit, storeHTML, size;
|
|
418
|
-
return __generator(this, function(_state) {
|
|
419
|
-
switch(_state.label){
|
|
420
|
-
case 0:
|
|
421
|
-
next = data;
|
|
422
|
-
limit = cacheConfig.staleLimit;
|
|
423
|
-
storeHTML = cacheAddition(html, cacheHash);
|
|
424
|
-
size = storeHTML.length;
|
|
425
|
-
return [
|
|
426
|
-
4,
|
|
427
|
-
next.caches.set(cacheHash, {
|
|
428
|
-
expireTime: Date.now() + cacheConfig.interval * 1e3,
|
|
429
|
-
limitTime: typeof limit === "number" ? Date.now() + limit * 1e3 : null,
|
|
430
|
-
cacheHash: cacheHash,
|
|
431
|
-
html: storeHTML,
|
|
432
|
-
size: size
|
|
433
|
-
})
|
|
434
|
-
];
|
|
435
|
-
case 1:
|
|
436
|
-
_state.sent();
|
|
437
|
-
_this.cache.set(cacheKey, next);
|
|
438
|
-
return [
|
|
439
|
-
2,
|
|
440
|
-
true
|
|
441
|
-
];
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
});
|
|
445
|
-
return function cacheSyncOrAsync() {
|
|
446
|
-
return _ref.apply(this, arguments);
|
|
447
|
-
};
|
|
448
|
-
}();
|
|
449
|
-
doCache = withCoalescedInvoke(cacheSyncOrAsync).bind(null, namespaceHash("stream", cacheHash), []);
|
|
450
|
-
return [
|
|
451
|
-
2,
|
|
452
|
-
maybeSync(doCache)(sync)
|
|
453
|
-
];
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
})();
|
|
457
|
-
}
|
|
458
|
-
},
|
|
459
|
-
{
|
|
460
|
-
key: "del",
|
|
461
|
-
value: function del(context, cacheHash) {
|
|
462
|
-
var _this = this;
|
|
463
|
-
return _asyncToGenerator(function() {
|
|
464
|
-
var cacheKey, data;
|
|
465
|
-
return __generator(this, function(_state) {
|
|
466
|
-
cacheKey = _this.generateRequestKey(context);
|
|
467
|
-
data = _this.cache.get(cacheKey);
|
|
468
|
-
data === null || data === void 0 ? void 0 : data.caches.del(cacheHash);
|
|
469
|
-
return [
|
|
470
|
-
2
|
|
471
|
-
];
|
|
472
|
-
});
|
|
473
|
-
})();
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
]);
|
|
477
|
-
return CacheManager;
|
|
478
|
-
}();
|
|
479
|
-
var manager;
|
|
480
|
-
function createCache() {
|
|
481
|
-
if (manager) {
|
|
482
|
-
return manager;
|
|
483
|
-
}
|
|
484
|
-
manager = new CacheManager({
|
|
485
|
-
max: 0
|
|
486
|
-
});
|
|
487
|
-
return manager;
|
|
488
|
-
}
|
|
489
|
-
function destroyCache() {
|
|
490
|
-
manager = null;
|
|
491
|
-
}
|
|
492
|
-
export { createCache, destroyCache };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|