@modern-js/prod-server 2.14.0 → 2.16.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 +21 -0
- package/dist/cjs/constants.js +15 -31
- package/dist/cjs/index.js +35 -37
- package/dist/cjs/libs/context/context.js +53 -66
- package/dist/cjs/libs/context/index.js +15 -28
- package/dist/cjs/libs/hook-api/index.js +59 -54
- package/dist/cjs/libs/hook-api/route.js +28 -30
- package/dist/cjs/libs/hook-api/template.js +30 -34
- package/dist/cjs/libs/loadConfig.js +74 -65
- package/dist/cjs/libs/logger.js +46 -37
- package/dist/cjs/libs/metrics.js +7 -25
- package/dist/cjs/libs/proxy.js +29 -46
- package/dist/cjs/libs/render/cache/__tests__/cache.fun.test.js +48 -64
- package/dist/cjs/libs/render/cache/__tests__/cache.test.js +53 -37
- package/dist/cjs/libs/render/cache/__tests__/cacheable.js +38 -34
- package/dist/cjs/libs/render/cache/__tests__/error-configuration.js +22 -30
- package/dist/cjs/libs/render/cache/__tests__/matched-cache.js +86 -46
- package/dist/cjs/libs/render/cache/index.js +17 -37
- package/dist/cjs/libs/render/cache/page-caches/index.js +12 -28
- package/dist/cjs/libs/render/cache/page-caches/lru.js +32 -40
- package/dist/cjs/libs/render/cache/spr.js +104 -111
- package/dist/cjs/libs/render/cache/type.js +4 -15
- package/dist/cjs/libs/render/cache/util.js +29 -53
- package/dist/cjs/libs/render/index.js +75 -73
- package/dist/cjs/libs/render/measure.js +19 -34
- package/dist/cjs/libs/render/reader.js +52 -61
- package/dist/cjs/libs/render/ssr.js +34 -66
- package/dist/cjs/libs/render/static.js +22 -45
- package/dist/cjs/libs/render/type.js +10 -28
- package/dist/cjs/libs/render/utils.js +17 -38
- package/dist/cjs/libs/route/index.js +32 -31
- package/dist/cjs/libs/route/matcher.js +38 -38
- package/dist/cjs/libs/route/route.js +29 -26
- package/dist/cjs/libs/serveFile.js +23 -41
- package/dist/cjs/server/index.js +101 -107
- package/dist/cjs/server/modernServer.js +191 -171
- package/dist/cjs/server/modernServerSplit.js +12 -30
- package/dist/cjs/type.js +4 -15
- package/dist/cjs/utils.js +50 -50
- package/dist/cjs/workerServer.js +26 -36
- package/dist/esm/constants.js +24 -25
- package/dist/esm/index.js +11 -10
- package/dist/esm/libs/context/context.js +271 -264
- package/dist/esm/libs/context/index.js +3 -3
- package/dist/esm/libs/hook-api/index.js +237 -223
- package/dist/esm/libs/hook-api/route.js +62 -60
- package/dist/esm/libs/hook-api/template.js +117 -115
- package/dist/esm/libs/loadConfig.js +68 -69
- package/dist/esm/libs/logger.js +188 -174
- package/dist/esm/libs/metrics.js +6 -3
- package/dist/esm/libs/proxy.js +236 -221
- package/dist/esm/libs/render/cache/__tests__/cache.fun.test.js +286 -267
- package/dist/esm/libs/render/cache/__tests__/cache.test.js +765 -745
- package/dist/esm/libs/render/cache/__tests__/cacheable.js +62 -63
- package/dist/esm/libs/render/cache/__tests__/error-configuration.js +42 -43
- package/dist/esm/libs/render/cache/__tests__/matched-cache.js +134 -135
- package/dist/esm/libs/render/cache/index.js +337 -326
- package/dist/esm/libs/render/cache/page-caches/index.js +147 -141
- package/dist/esm/libs/render/cache/page-caches/lru.js +78 -76
- package/dist/esm/libs/render/cache/spr.js +465 -456
- package/dist/esm/libs/render/cache/type.js +1 -1
- package/dist/esm/libs/render/cache/util.js +266 -246
- package/dist/esm/libs/render/index.js +226 -218
- package/dist/esm/libs/render/measure.js +136 -128
- package/dist/esm/libs/render/reader.js +315 -304
- package/dist/esm/libs/render/ssr.js +214 -209
- package/dist/esm/libs/render/static.js +208 -198
- package/dist/esm/libs/render/type.js +6 -7
- package/dist/esm/libs/render/utils.js +8 -9
- package/dist/esm/libs/route/index.js +134 -123
- package/dist/esm/libs/route/matcher.js +140 -130
- package/dist/esm/libs/route/route.js +36 -37
- package/dist/esm/libs/serveFile.js +177 -168
- package/dist/esm/server/index.js +578 -549
- package/dist/esm/server/modernServer.js +1137 -1074
- package/dist/esm/server/modernServerSplit.js +344 -328
- package/dist/esm/type.js +1 -1
- package/dist/esm/utils.js +133 -124
- package/dist/esm/workerServer.js +226 -220
- package/dist/esm-node/constants.js +7 -14
- package/dist/esm-node/index.js +4 -9
- package/dist/esm-node/libs/context/context.js +32 -25
- package/dist/esm-node/libs/context/index.js +2 -5
- package/dist/esm-node/libs/hook-api/index.js +40 -21
- package/dist/esm-node/libs/hook-api/route.js +21 -8
- package/dist/esm-node/libs/hook-api/template.js +19 -14
- package/dist/esm-node/libs/loadConfig.js +11 -28
- package/dist/esm-node/libs/logger.js +37 -17
- package/dist/esm-node/libs/metrics.js +1 -3
- package/dist/esm-node/libs/proxy.js +14 -22
- package/dist/esm-node/libs/render/cache/__tests__/cache.fun.test.js +25 -36
- package/dist/esm-node/libs/render/cache/__tests__/cache.test.js +23 -11
- package/dist/esm-node/libs/render/cache/__tests__/cacheable.js +32 -13
- package/dist/esm-node/libs/render/cache/__tests__/error-configuration.js +16 -9
- package/dist/esm-node/libs/render/cache/__tests__/matched-cache.js +80 -25
- package/dist/esm-node/libs/render/cache/index.js +3 -10
- package/dist/esm-node/libs/render/cache/page-caches/index.js +4 -5
- package/dist/esm-node/libs/render/cache/page-caches/lru.js +20 -8
- package/dist/esm-node/libs/render/cache/spr.js +79 -80
- package/dist/esm-node/libs/render/cache/type.js +1 -0
- package/dist/esm-node/libs/render/cache/util.js +13 -23
- package/dist/esm-node/libs/render/index.js +10 -28
- package/dist/esm-node/libs/render/measure.js +7 -13
- package/dist/esm-node/libs/render/reader.js +31 -26
- package/dist/esm-node/libs/render/ssr.js +5 -21
- package/dist/esm-node/libs/render/static.js +1 -4
- package/dist/esm-node/libs/render/type.js +3 -6
- package/dist/esm-node/libs/render/utils.js +6 -18
- package/dist/esm-node/libs/route/index.js +20 -9
- package/dist/esm-node/libs/route/matcher.js +28 -17
- package/dist/esm-node/libs/route/route.js +23 -5
- package/dist/esm-node/libs/serveFile.js +2 -6
- package/dist/esm-node/server/index.js +72 -75
- package/dist/esm-node/server/modernServer.js +102 -130
- package/dist/esm-node/server/modernServerSplit.js +1 -4
- package/dist/esm-node/type.js +1 -0
- package/dist/esm-node/utils.js +41 -32
- package/dist/esm-node/workerServer.js +9 -10
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/server/modernServer.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +12 -8
|
@@ -1,33 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var page_caches_exports = {};
|
|
19
|
-
__export(page_caches_exports, {
|
|
20
|
-
createPageCaches: () => createPageCaches
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
21
4
|
});
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
Object.defineProperty(exports, "createPageCaches", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => createPageCaches
|
|
8
|
+
});
|
|
9
|
+
const _lru = require("./lru");
|
|
24
10
|
async function createPageCaches(max) {
|
|
25
|
-
const constructorOptions = {
|
|
26
|
-
|
|
11
|
+
const constructorOptions = {
|
|
12
|
+
max
|
|
13
|
+
};
|
|
14
|
+
const cacheInstance = new _lru.LRUCaches(constructorOptions);
|
|
27
15
|
await cacheInstance.init();
|
|
28
16
|
return cacheInstance;
|
|
29
17
|
}
|
|
30
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
-
0 && (module.exports = {
|
|
32
|
-
createPageCaches
|
|
33
|
-
});
|
|
@@ -1,41 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var lru_exports = {};
|
|
29
|
-
__export(lru_exports, {
|
|
30
|
-
LRUCaches: () => LRUCaches
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
31
4
|
});
|
|
32
|
-
|
|
33
|
-
|
|
5
|
+
Object.defineProperty(exports, "LRUCaches", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => LRUCaches
|
|
8
|
+
});
|
|
9
|
+
const _lrucache = /* @__PURE__ */ _interop_require_default(require("lru-cache"));
|
|
10
|
+
function _define_property(obj, key, value) {
|
|
11
|
+
if (key in obj) {
|
|
12
|
+
Object.defineProperty(obj, key, {
|
|
13
|
+
value,
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
obj[key] = value;
|
|
20
|
+
}
|
|
21
|
+
return obj;
|
|
22
|
+
}
|
|
23
|
+
function _interop_require_default(obj) {
|
|
24
|
+
return obj && obj.__esModule ? obj : {
|
|
25
|
+
default: obj
|
|
26
|
+
};
|
|
27
|
+
}
|
|
34
28
|
class LRUCaches {
|
|
35
|
-
constructor(options) {
|
|
36
|
-
this.max = options.max;
|
|
37
|
-
this.caches = new import_lru_cache.default(this.max);
|
|
38
|
-
}
|
|
39
29
|
init() {
|
|
40
30
|
return Promise.resolve();
|
|
41
31
|
}
|
|
@@ -55,8 +45,10 @@ class LRUCaches {
|
|
|
55
45
|
del(key) {
|
|
56
46
|
this.caches.del(key);
|
|
57
47
|
}
|
|
48
|
+
constructor(options) {
|
|
49
|
+
_define_property(this, "caches", void 0);
|
|
50
|
+
_define_property(this, "max", void 0);
|
|
51
|
+
this.max = options.max;
|
|
52
|
+
this.caches = new _lrucache.default(this.max);
|
|
53
|
+
}
|
|
58
54
|
}
|
|
59
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
-
0 && (module.exports = {
|
|
61
|
-
LRUCaches
|
|
62
|
-
});
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
8
6
|
for (var name in all)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var spr_exports = {};
|
|
29
|
-
__export(spr_exports, {
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
30
13
|
createCache: () => createCache,
|
|
31
14
|
destroyCache: () => destroyCache
|
|
32
15
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
16
|
+
const _crypto = /* @__PURE__ */ _interop_require_default(require("crypto"));
|
|
17
|
+
const _lrucache = /* @__PURE__ */ _interop_require_default(require("lru-cache"));
|
|
18
|
+
const _utils = require("@modern-js/utils");
|
|
19
|
+
const _util = require("./util");
|
|
20
|
+
const _pagecaches = require("./page-caches");
|
|
21
|
+
function _define_property(obj, key, value) {
|
|
22
|
+
if (key in obj) {
|
|
23
|
+
Object.defineProperty(obj, key, {
|
|
24
|
+
value,
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
obj[key] = value;
|
|
31
|
+
}
|
|
32
|
+
return obj;
|
|
33
|
+
}
|
|
34
|
+
function _interop_require_default(obj) {
|
|
35
|
+
return obj && obj.__esModule ? obj : {
|
|
36
|
+
default: obj
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
39
|
const MAX_CACHE_EACH_REQ = Number(process.env.ROUTE_CACHE_LIMIT) || 10;
|
|
40
40
|
const MAX_SIZE_EACH_CLUSTER = Number(process.env.CLUSTER_CACHE_LIMIT) || 100;
|
|
41
41
|
const BASE_LEVEL = 0;
|
|
@@ -43,54 +43,8 @@ const QUERY_LEVEL = 1;
|
|
|
43
43
|
const HEADER_LEVEL = 2;
|
|
44
44
|
const QUERY_HEADER_LEVEL = 3;
|
|
45
45
|
class CacheManager {
|
|
46
|
-
constructor(cacheOptions) {
|
|
47
|
-
this.find = (() => {
|
|
48
|
-
{
|
|
49
|
-
const _this = this;
|
|
50
|
-
return {
|
|
51
|
-
[(0, import_util.fname)(BASE_LEVEL)](context, cacheKey) {
|
|
52
|
-
return _this.md5(cacheKey);
|
|
53
|
-
},
|
|
54
|
-
[(0, import_util.fname)(QUERY_LEVEL)](context, cacheKey, data) {
|
|
55
|
-
const queryFactor = _this.queryFactor(context, data);
|
|
56
|
-
if (!queryFactor) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
return _this.md5((0, import_util.connectFactor)(cacheKey, queryFactor));
|
|
60
|
-
},
|
|
61
|
-
[(0, import_util.fname)(HEADER_LEVEL)](context, cacheKey, data) {
|
|
62
|
-
const headerFactor = _this.headerFactor(context, data);
|
|
63
|
-
if (!headerFactor) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
return _this.md5((0, import_util.connectFactor)(cacheKey, headerFactor));
|
|
67
|
-
},
|
|
68
|
-
[(0, import_util.fname)(QUERY_HEADER_LEVEL)](context, cacheKey, data) {
|
|
69
|
-
const queryFactor = _this.queryFactor(context, data);
|
|
70
|
-
const headerFactor = _this.headerFactor(context, data);
|
|
71
|
-
if (!queryFactor || !headerFactor) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
return _this.md5((0, import_util.connectFactor)(cacheKey, headerFactor, queryFactor));
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
})();
|
|
79
|
-
this.cacheOptions = cacheOptions;
|
|
80
|
-
this.cache = new import_lru_cache.default({
|
|
81
|
-
max: Math.min(MAX_SIZE_EACH_CLUSTER, 600) * 1024 * 1024,
|
|
82
|
-
// 默认存 100M,最大 600M
|
|
83
|
-
length(n) {
|
|
84
|
-
const len = n.caches.keys().reduce((total, cur) => {
|
|
85
|
-
var _a;
|
|
86
|
-
return total + (((_a = n.caches.peek(cur)) == null ? void 0 : _a.size) || 0);
|
|
87
|
-
}, 1);
|
|
88
|
-
return len;
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
46
|
md5(content) {
|
|
93
|
-
const md5 =
|
|
47
|
+
const md5 = _crypto.default.createHash("md5");
|
|
94
48
|
return md5.update(content).digest("hex");
|
|
95
49
|
}
|
|
96
50
|
generateRequestKey(context) {
|
|
@@ -111,21 +65,24 @@ class CacheManager {
|
|
|
111
65
|
}
|
|
112
66
|
factor(keys, obj, matches = {}) {
|
|
113
67
|
keys.sort();
|
|
114
|
-
const getValue = (0,
|
|
68
|
+
const getValue = (0, _util.valueFactory)(obj);
|
|
115
69
|
const factorAry = keys.reduce((ary, key) => {
|
|
116
70
|
let value = getValue(key) || "";
|
|
117
71
|
const matcher = matches[key];
|
|
118
72
|
if (matcher) {
|
|
119
73
|
value = this.replaceValue(value, matcher);
|
|
120
74
|
}
|
|
121
|
-
return ary.concat([
|
|
75
|
+
return ary.concat([
|
|
76
|
+
key,
|
|
77
|
+
value
|
|
78
|
+
]);
|
|
122
79
|
}, []);
|
|
123
80
|
return factorAry.join(",");
|
|
124
81
|
}
|
|
125
82
|
queryFactor(context, data) {
|
|
126
|
-
var
|
|
127
|
-
const queryKeys = (
|
|
128
|
-
const queryMatches = (
|
|
83
|
+
var _data_includes, _data_matches;
|
|
84
|
+
const queryKeys = (_data_includes = data.includes) === null || _data_includes === void 0 ? void 0 : _data_includes.query;
|
|
85
|
+
const queryMatches = (_data_matches = data.matches) === null || _data_matches === void 0 ? void 0 : _data_matches.query;
|
|
129
86
|
if (!queryKeys || queryKeys.length === 0) {
|
|
130
87
|
return null;
|
|
131
88
|
}
|
|
@@ -134,9 +91,9 @@ class CacheManager {
|
|
|
134
91
|
return queryFactor;
|
|
135
92
|
}
|
|
136
93
|
headerFactor(context, data) {
|
|
137
|
-
var
|
|
138
|
-
const headerKeys = (
|
|
139
|
-
const headerMatches = (
|
|
94
|
+
var _data_includes, _data_matches;
|
|
95
|
+
const headerKeys = (_data_includes = data.includes) === null || _data_includes === void 0 ? void 0 : _data_includes.header;
|
|
96
|
+
const headerMatches = (_data_matches = data.matches) === null || _data_matches === void 0 ? void 0 : _data_matches.header;
|
|
140
97
|
if (!headerKeys || headerKeys.length === 0) {
|
|
141
98
|
return null;
|
|
142
99
|
}
|
|
@@ -146,7 +103,7 @@ class CacheManager {
|
|
|
146
103
|
}
|
|
147
104
|
async best(context, cacheKey, data) {
|
|
148
105
|
const { level } = data;
|
|
149
|
-
const cacheHash = this.find[(0,
|
|
106
|
+
const cacheHash = this.find[(0, _util.fname)(level)](context, cacheKey, data);
|
|
150
107
|
if (!cacheHash) {
|
|
151
108
|
return null;
|
|
152
109
|
}
|
|
@@ -177,7 +134,7 @@ class CacheManager {
|
|
|
177
134
|
const isGarbage = limitTime ? Date.now() - limitTime > 0 : false;
|
|
178
135
|
return {
|
|
179
136
|
content: html || "",
|
|
180
|
-
contentType:
|
|
137
|
+
contentType: _utils.mime.contentType("html"),
|
|
181
138
|
isStale,
|
|
182
139
|
isGarbage,
|
|
183
140
|
hash: cacheHash
|
|
@@ -190,21 +147,17 @@ class CacheManager {
|
|
|
190
147
|
const cacheKey = this.generateRequestKey(context);
|
|
191
148
|
let data = this.cache.get(cacheKey);
|
|
192
149
|
if (!data) {
|
|
193
|
-
const caches = await (0,
|
|
150
|
+
const caches = await (0, _pagecaches.createPageCaches)(MAX_CACHE_EACH_REQ);
|
|
194
151
|
data = this.createCacheContent(cacheConfig, caches);
|
|
195
152
|
}
|
|
196
|
-
const cacheHash = this.find[(0,
|
|
197
|
-
context,
|
|
198
|
-
cacheKey,
|
|
199
|
-
data
|
|
200
|
-
);
|
|
153
|
+
const cacheHash = this.find[(0, _util.fname)(cacheConfig.level)](context, cacheKey, data);
|
|
201
154
|
if (!cacheHash) {
|
|
202
155
|
return false;
|
|
203
156
|
}
|
|
204
157
|
const cacheSyncOrAsync = async () => {
|
|
205
158
|
const next = data;
|
|
206
159
|
const limit = cacheConfig.staleLimit;
|
|
207
|
-
const storeHTML = (0,
|
|
160
|
+
const storeHTML = (0, _util.cacheAddition)(html, cacheHash);
|
|
208
161
|
const size = storeHTML.length;
|
|
209
162
|
await next.caches.set(cacheHash, {
|
|
210
163
|
expireTime: Date.now() + cacheConfig.interval * 1e3,
|
|
@@ -216,17 +169,60 @@ class CacheManager {
|
|
|
216
169
|
this.cache.set(cacheKey, next);
|
|
217
170
|
return true;
|
|
218
171
|
};
|
|
219
|
-
const doCache = (0,
|
|
220
|
-
|
|
221
|
-
(0, import_util.namespaceHash)("stream", cacheHash),
|
|
222
|
-
[]
|
|
223
|
-
);
|
|
224
|
-
return (0, import_util.maybeSync)(doCache)(sync);
|
|
172
|
+
const doCache = (0, _util.withCoalescedInvoke)(cacheSyncOrAsync).bind(null, (0, _util.namespaceHash)("stream", cacheHash), []);
|
|
173
|
+
return (0, _util.maybeSync)(doCache)(sync);
|
|
225
174
|
}
|
|
226
175
|
async del(context, cacheHash) {
|
|
227
176
|
const cacheKey = this.generateRequestKey(context);
|
|
228
177
|
const data = this.cache.get(cacheKey);
|
|
229
|
-
data
|
|
178
|
+
data === null || data === void 0 ? void 0 : data.caches.del(cacheHash);
|
|
179
|
+
}
|
|
180
|
+
constructor(cacheOptions) {
|
|
181
|
+
_define_property(this, "cache", void 0);
|
|
182
|
+
_define_property(this, "cacheOptions", void 0);
|
|
183
|
+
_define_property(this, "find", (() => {
|
|
184
|
+
{
|
|
185
|
+
const _this = this;
|
|
186
|
+
return {
|
|
187
|
+
[(0, _util.fname)(BASE_LEVEL)](context, cacheKey) {
|
|
188
|
+
return _this.md5(cacheKey);
|
|
189
|
+
},
|
|
190
|
+
[(0, _util.fname)(QUERY_LEVEL)](context, cacheKey, data) {
|
|
191
|
+
const queryFactor = _this.queryFactor(context, data);
|
|
192
|
+
if (!queryFactor) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
return _this.md5((0, _util.connectFactor)(cacheKey, queryFactor));
|
|
196
|
+
},
|
|
197
|
+
[(0, _util.fname)(HEADER_LEVEL)](context, cacheKey, data) {
|
|
198
|
+
const headerFactor = _this.headerFactor(context, data);
|
|
199
|
+
if (!headerFactor) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
return _this.md5((0, _util.connectFactor)(cacheKey, headerFactor));
|
|
203
|
+
},
|
|
204
|
+
[(0, _util.fname)(QUERY_HEADER_LEVEL)](context, cacheKey, data) {
|
|
205
|
+
const queryFactor = _this.queryFactor(context, data);
|
|
206
|
+
const headerFactor = _this.headerFactor(context, data);
|
|
207
|
+
if (!queryFactor || !headerFactor) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
return _this.md5((0, _util.connectFactor)(cacheKey, headerFactor, queryFactor));
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
})());
|
|
215
|
+
this.cacheOptions = cacheOptions;
|
|
216
|
+
this.cache = new _lrucache.default({
|
|
217
|
+
max: Math.min(MAX_SIZE_EACH_CLUSTER, 600) * 1024 * 1024,
|
|
218
|
+
length(n) {
|
|
219
|
+
const len = n.caches.keys().reduce((total, cur) => {
|
|
220
|
+
var _n_caches_peek;
|
|
221
|
+
return total + (((_n_caches_peek = n.caches.peek(cur)) === null || _n_caches_peek === void 0 ? void 0 : _n_caches_peek.size) || 0);
|
|
222
|
+
}, 1);
|
|
223
|
+
return len;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
230
226
|
}
|
|
231
227
|
}
|
|
232
228
|
let manager;
|
|
@@ -234,14 +230,11 @@ function createCache() {
|
|
|
234
230
|
if (manager) {
|
|
235
231
|
return manager;
|
|
236
232
|
}
|
|
237
|
-
manager = new CacheManager({
|
|
233
|
+
manager = new CacheManager({
|
|
234
|
+
max: 0
|
|
235
|
+
});
|
|
238
236
|
return manager;
|
|
239
237
|
}
|
|
240
238
|
function destroyCache() {
|
|
241
239
|
manager = null;
|
|
242
240
|
}
|
|
243
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
244
|
-
0 && (module.exports = {
|
|
245
|
-
createCache,
|
|
246
|
-
destroyCache
|
|
247
|
-
});
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
-
var type_exports = {};
|
|
15
|
-
module.exports = __toCommonJS(type_exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
@@ -1,43 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
8
6
|
for (var name in all)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var util_exports = {};
|
|
29
|
-
__export(util_exports, {
|
|
30
|
-
cacheAddition: () => cacheAddition,
|
|
31
|
-
connectFactor: () => connectFactor,
|
|
32
|
-
fname: () => fname,
|
|
33
|
-
getTime: () => getTime,
|
|
34
|
-
maybeSync: () => maybeSync,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
35
13
|
namespaceHash: () => namespaceHash,
|
|
14
|
+
fname: () => fname,
|
|
15
|
+
connectFactor: () => connectFactor,
|
|
36
16
|
valueFactory: () => valueFactory,
|
|
37
|
-
|
|
17
|
+
getTime: () => getTime,
|
|
18
|
+
cacheAddition: () => cacheAddition,
|
|
19
|
+
withCoalescedInvoke: () => withCoalescedInvoke,
|
|
20
|
+
maybeSync: () => maybeSync
|
|
38
21
|
});
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
const _url = /* @__PURE__ */ _interop_require_default(require("url"));
|
|
23
|
+
function _interop_require_default(obj) {
|
|
24
|
+
return obj && obj.__esModule ? obj : {
|
|
25
|
+
default: obj
|
|
26
|
+
};
|
|
27
|
+
}
|
|
41
28
|
function namespaceHash(namespace, hash) {
|
|
42
29
|
return `${namespace}/${hash}`;
|
|
43
30
|
}
|
|
@@ -48,7 +35,7 @@ function connectFactor(...args) {
|
|
|
48
35
|
return args.join("-");
|
|
49
36
|
}
|
|
50
37
|
function valueFactory(obj) {
|
|
51
|
-
if (obj instanceof
|
|
38
|
+
if (obj instanceof _url.default.URLSearchParams) {
|
|
52
39
|
return function(key) {
|
|
53
40
|
return obj.get(key);
|
|
54
41
|
};
|
|
@@ -67,10 +54,7 @@ function getTime([s, ns]) {
|
|
|
67
54
|
}
|
|
68
55
|
const RE_START_IN_HEAD = /<head>/;
|
|
69
56
|
function cacheAddition(html, hash) {
|
|
70
|
-
const additionHtml = html.replace(
|
|
71
|
-
RE_START_IN_HEAD,
|
|
72
|
-
`<head><meta name="x-moden-spr" content="${hash}">`
|
|
73
|
-
);
|
|
57
|
+
const additionHtml = html.replace(RE_START_IN_HEAD, `<head><meta name="x-moden-spr" content="${hash}">`);
|
|
74
58
|
return additionHtml;
|
|
75
59
|
}
|
|
76
60
|
const globalInvokeCache = /* @__PURE__ */ new Map();
|
|
@@ -88,7 +72,10 @@ function withCoalescedInvoke(func) {
|
|
|
88
72
|
}
|
|
89
73
|
const future = __wrapper().then((res) => {
|
|
90
74
|
globalInvokeCache.delete(key);
|
|
91
|
-
return {
|
|
75
|
+
return {
|
|
76
|
+
isOrigin: true,
|
|
77
|
+
value: res
|
|
78
|
+
};
|
|
92
79
|
}).catch((err) => {
|
|
93
80
|
globalInvokeCache.delete(key);
|
|
94
81
|
throw err;
|
|
@@ -107,14 +94,3 @@ function maybeSync(fn) {
|
|
|
107
94
|
}
|
|
108
95
|
};
|
|
109
96
|
}
|
|
110
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
-
0 && (module.exports = {
|
|
112
|
-
cacheAddition,
|
|
113
|
-
connectFactor,
|
|
114
|
-
fname,
|
|
115
|
-
getTime,
|
|
116
|
-
maybeSync,
|
|
117
|
-
namespaceHash,
|
|
118
|
-
valueFactory,
|
|
119
|
-
withCoalescedInvoke
|
|
120
|
-
});
|