@modern-js/prod-server 2.0.0-beta.3 → 2.0.0-beta.6
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 +139 -0
- package/dist/js/modern/constants.js +32 -25
- package/dist/js/modern/index.js +11 -6
- package/dist/js/modern/libs/context/context.js +52 -84
- package/dist/js/modern/libs/context/index.js +5 -2
- package/dist/js/modern/libs/hook-api/index.js +44 -35
- package/dist/js/modern/libs/hook-api/route.js +6 -7
- package/dist/js/modern/libs/hook-api/template.js +20 -34
- package/dist/js/modern/libs/loadConfig.js +45 -24
- package/dist/js/modern/libs/metrics.js +3 -4
- package/dist/js/modern/libs/proxy.js +68 -37
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +112 -67
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +246 -216
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +43 -49
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +36 -34
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +83 -113
- package/dist/js/modern/libs/render/cache/index.js +88 -54
- package/dist/js/modern/libs/render/cache/page-caches/index.js +31 -8
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +6 -6
- package/dist/js/modern/libs/render/cache/spr.js +133 -117
- package/dist/js/modern/libs/render/cache/type.js +0 -1
- package/dist/js/modern/libs/render/cache/util.js +71 -39
- package/dist/js/modern/libs/render/index.js +76 -56
- package/dist/js/modern/libs/render/measure.js +38 -27
- package/dist/js/modern/libs/render/reader.js +65 -62
- package/dist/js/modern/libs/render/ssr.js +50 -32
- package/dist/js/modern/libs/render/static.js +50 -33
- package/dist/js/modern/libs/render/type.js +9 -6
- package/dist/js/modern/libs/route/index.js +8 -15
- package/dist/js/modern/libs/route/matcher.js +20 -34
- package/dist/js/modern/libs/route/route.js +9 -18
- package/dist/js/modern/libs/serve-file.js +33 -20
- package/dist/js/modern/server/index.js +150 -145
- package/dist/js/modern/server/modern-server-split.js +46 -12
- package/dist/js/modern/server/modern-server.js +384 -422
- package/dist/js/modern/type.js +0 -1
- package/dist/js/modern/utils.js +62 -43
- package/dist/js/modern/worker-server.js +34 -14
- package/dist/js/node/constants.js +53 -30
- package/dist/js/node/index.js +37 -57
- package/dist/js/node/libs/context/context.js +83 -94
- package/dist/js/node/libs/context/index.js +28 -13
- package/dist/js/node/libs/hook-api/index.js +76 -48
- package/dist/js/node/libs/hook-api/route.js +26 -11
- package/dist/js/node/libs/hook-api/template.js +41 -39
- package/dist/js/node/libs/loadConfig.js +73 -35
- package/dist/js/node/libs/metrics.js +25 -9
- package/dist/js/node/libs/proxy.js +89 -44
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +99 -56
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +147 -128
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +65 -55
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +58 -40
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +105 -119
- package/dist/js/node/libs/render/cache/index.js +110 -64
- package/dist/js/node/libs/render/cache/page-caches/index.js +54 -14
- package/dist/js/node/libs/render/cache/page-caches/lru.js +33 -12
- package/dist/js/node/libs/render/cache/spr.js +161 -129
- package/dist/js/node/libs/render/cache/type.js +15 -5
- package/dist/js/node/libs/render/cache/util.js +99 -45
- package/dist/js/node/libs/render/index.js +106 -67
- package/dist/js/node/libs/render/measure.js +58 -31
- package/dist/js/node/libs/render/reader.js +95 -70
- package/dist/js/node/libs/render/ssr.js +80 -47
- package/dist/js/node/libs/render/static.js +79 -40
- package/dist/js/node/libs/render/type.js +31 -12
- package/dist/js/node/libs/route/index.js +31 -26
- package/dist/js/node/libs/route/matcher.js +40 -41
- package/dist/js/node/libs/route/route.js +29 -22
- package/dist/js/node/libs/serve-file.js +66 -32
- package/dist/js/node/server/index.js +168 -160
- package/dist/js/node/server/modern-server-split.js +72 -22
- package/dist/js/node/server/modern-server.js +403 -445
- package/dist/js/node/type.js +15 -3
- package/dist/js/node/utils.js +85 -52
- package/dist/js/node/worker-server.js +57 -21
- package/dist/js/treeshaking/constants.js +26 -25
- package/dist/js/treeshaking/index.js +10 -10
- package/dist/js/treeshaking/libs/context/context.js +268 -237
- package/dist/js/treeshaking/libs/context/index.js +3 -3
- package/dist/js/treeshaking/libs/hook-api/index.js +267 -143
- package/dist/js/treeshaking/libs/hook-api/route.js +65 -30
- package/dist/js/treeshaking/libs/hook-api/template.js +121 -85
- package/dist/js/treeshaking/libs/loadConfig.js +80 -37
- package/dist/js/treeshaking/libs/metrics.js +4 -10
- package/dist/js/treeshaking/libs/proxy.js +240 -76
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +288 -121
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +772 -455
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +65 -51
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -35
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +144 -118
- package/dist/js/treeshaking/libs/render/cache/index.js +337 -175
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +151 -27
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +80 -42
- package/dist/js/treeshaking/libs/render/cache/spr.js +470 -340
- package/dist/js/treeshaking/libs/render/cache/type.js +1 -1
- package/dist/js/treeshaking/libs/render/cache/util.js +271 -92
- package/dist/js/treeshaking/libs/render/index.js +228 -95
- package/dist/js/treeshaking/libs/render/measure.js +142 -57
- package/dist/js/treeshaking/libs/render/reader.js +325 -177
- package/dist/js/treeshaking/libs/render/ssr.js +220 -95
- package/dist/js/treeshaking/libs/render/static.js +210 -78
- package/dist/js/treeshaking/libs/render/type.js +7 -6
- package/dist/js/treeshaking/libs/route/index.js +125 -89
- package/dist/js/treeshaking/libs/route/matcher.js +132 -107
- package/dist/js/treeshaking/libs/route/route.js +40 -26
- package/dist/js/treeshaking/libs/serve-file.js +177 -68
- package/dist/js/treeshaking/server/index.js +493 -327
- package/dist/js/treeshaking/server/modern-server-split.js +352 -144
- package/dist/js/treeshaking/server/modern-server.js +1048 -909
- package/dist/js/treeshaking/type.js +1 -1
- package/dist/js/treeshaking/utils.js +138 -81
- package/dist/js/treeshaking/worker-server.js +176 -55
- package/dist/types/index.d.ts +2 -0
- package/dist/types/libs/context/context.d.ts +4 -1
- package/dist/types/libs/loadConfig.d.ts +1 -0
- package/dist/types/libs/render/cache/index.d.ts +2 -0
- package/dist/types/libs/render/cache/spr.d.ts +2 -0
- package/dist/types/libs/route/route.d.ts +0 -1
- package/dist/types/server/index.d.ts +3 -0
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/worker-server.d.ts +1 -2
- package/package.json +7 -14
- package/dist/js/modern/libs/render/modern/browser-list.js +0 -7
- package/dist/js/modern/libs/render/modern/index.js +0 -37
- package/dist/js/node/libs/render/modern/browser-list.js +0 -14
- package/dist/js/node/libs/render/modern/index.js +0 -46
- package/dist/js/treeshaking/libs/render/modern/browser-list.js +0 -7
- package/dist/js/treeshaking/libs/render/modern/index.js +0 -39
- package/dist/types/libs/render/modern/browser-list.d.ts +0 -1
- package/dist/types/libs/render/modern/index.d.ts +0 -3
|
@@ -1,121 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
const matchedCacheableAry = [
|
|
2
|
+
[
|
|
3
|
+
{
|
|
4
|
+
requestOpt: {
|
|
5
|
+
url: "/level-one",
|
|
6
|
+
headers: {},
|
|
7
|
+
query: { name: "byted" }
|
|
8
|
+
},
|
|
9
|
+
cacheConfig: {
|
|
10
|
+
level: 1,
|
|
11
|
+
includes: { query: ["name"] },
|
|
12
|
+
matches: { query: { name: { weixin: "^byted" } } }
|
|
13
|
+
},
|
|
14
|
+
content: "level1"
|
|
13
15
|
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
content: 'level1'
|
|
23
|
-
}, {
|
|
24
|
-
url: '/level-one',
|
|
25
|
-
headers: {},
|
|
26
|
-
query: {
|
|
27
|
-
name: 'byted_likely'
|
|
28
|
-
}
|
|
29
|
-
}, {
|
|
30
|
-
url: '/level-one',
|
|
31
|
-
headers: {},
|
|
32
|
-
query: {
|
|
33
|
-
name: 'not_byted'
|
|
34
|
-
}
|
|
35
|
-
}], [{
|
|
36
|
-
requestOpt: {
|
|
37
|
-
url: '/level-two',
|
|
38
|
-
query: {},
|
|
39
|
-
headers: {
|
|
40
|
-
age: '17'
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
cacheConfig: {
|
|
44
|
-
level: 2,
|
|
45
|
-
includes: {
|
|
46
|
-
header: ['age']
|
|
16
|
+
{
|
|
17
|
+
url: "/level-one",
|
|
18
|
+
headers: {},
|
|
19
|
+
query: { name: "byted_likely" }
|
|
47
20
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
}
|
|
21
|
+
{
|
|
22
|
+
url: "/level-one",
|
|
23
|
+
headers: {},
|
|
24
|
+
query: { name: "not_byted" }
|
|
54
25
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}], [{
|
|
70
|
-
requestOpt: {
|
|
71
|
-
url: '/level-three',
|
|
72
|
-
headers: {
|
|
73
|
-
age: '17'
|
|
26
|
+
],
|
|
27
|
+
[
|
|
28
|
+
{
|
|
29
|
+
requestOpt: {
|
|
30
|
+
url: "/level-two",
|
|
31
|
+
query: {},
|
|
32
|
+
headers: { age: "17" }
|
|
33
|
+
},
|
|
34
|
+
cacheConfig: {
|
|
35
|
+
level: 2,
|
|
36
|
+
includes: { header: ["age"] },
|
|
37
|
+
matches: { header: { age: { one: "^1" } } }
|
|
38
|
+
},
|
|
39
|
+
content: "level2"
|
|
74
40
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
cacheConfig: {
|
|
80
|
-
level: 3,
|
|
81
|
-
includes: {
|
|
82
|
-
query: ['name'],
|
|
83
|
-
header: ['age']
|
|
41
|
+
{
|
|
42
|
+
url: "/level-two",
|
|
43
|
+
query: {},
|
|
44
|
+
headers: { age: "11" }
|
|
84
45
|
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
46
|
+
{
|
|
47
|
+
url: "/level-two",
|
|
48
|
+
query: {},
|
|
49
|
+
headers: { age: "22" }
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
{
|
|
54
|
+
requestOpt: {
|
|
55
|
+
url: "/level-three",
|
|
56
|
+
headers: { age: "17" },
|
|
57
|
+
query: { name: "byted" }
|
|
90
58
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
59
|
+
cacheConfig: {
|
|
60
|
+
level: 3,
|
|
61
|
+
includes: {
|
|
62
|
+
query: ["name"],
|
|
63
|
+
header: ["age"]
|
|
64
|
+
},
|
|
65
|
+
matches: {
|
|
66
|
+
query: { name: { weixin: "^byted" } },
|
|
67
|
+
header: { age: { one: "^1" } }
|
|
94
68
|
}
|
|
95
|
-
}
|
|
69
|
+
},
|
|
70
|
+
content: "level3"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
url: "/level-three",
|
|
74
|
+
query: { name: "byted_likely" },
|
|
75
|
+
headers: { age: "19" }
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
url: "/level-three",
|
|
79
|
+
query: { name: "byted_likely" },
|
|
80
|
+
headers: {}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
url: "/level-three",
|
|
84
|
+
query: { name: "not_byted" },
|
|
85
|
+
headers: { age: "19" }
|
|
96
86
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
name: 'byted_likely'
|
|
103
|
-
},
|
|
104
|
-
headers: {
|
|
105
|
-
age: '19'
|
|
106
|
-
}
|
|
107
|
-
}, {
|
|
108
|
-
url: '/level-three',
|
|
109
|
-
query: {
|
|
110
|
-
name: 'byted_likely'
|
|
111
|
-
},
|
|
112
|
-
headers: {}
|
|
113
|
-
}, {
|
|
114
|
-
url: '/level-three',
|
|
115
|
-
query: {
|
|
116
|
-
name: 'not_byted'
|
|
117
|
-
},
|
|
118
|
-
headers: {
|
|
119
|
-
age: '19'
|
|
120
|
-
}
|
|
121
|
-
}]];
|
|
87
|
+
]
|
|
88
|
+
];
|
|
89
|
+
export {
|
|
90
|
+
matchedCacheableAry
|
|
91
|
+
};
|
|
@@ -1,81 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __async = (__this, __arguments, generator) => {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
var fulfilled = (value) => {
|
|
20
|
+
try {
|
|
21
|
+
step(generator.next(value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var rejected = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.throw(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
import { Transform } from "stream";
|
|
5
38
|
import { ERROR_DIGEST } from "../../../constants";
|
|
6
39
|
import { createCache } from "./spr";
|
|
7
40
|
import { namespaceHash, withCoalescedInvoke } from "./util";
|
|
8
|
-
|
|
41
|
+
var cache_default = (renderFn, ctx) => {
|
|
9
42
|
const sprCache = createCache();
|
|
10
|
-
const doRender =
|
|
11
|
-
const cacheContext =
|
|
43
|
+
const doRender = (context) => __async(void 0, null, function* () {
|
|
44
|
+
const cacheContext = __spreadValues({
|
|
12
45
|
entry: context.entryName
|
|
13
46
|
}, context.request);
|
|
14
|
-
const cacheFile =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
47
|
+
const cacheFile = yield sprCache.get(cacheContext);
|
|
48
|
+
function afterRender(source, onAfterRender) {
|
|
49
|
+
return __async(this, null, function* () {
|
|
50
|
+
if (!source) {
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
if (typeof source === "string") {
|
|
54
|
+
yield onAfterRender(source);
|
|
55
|
+
return source;
|
|
56
|
+
} else {
|
|
57
|
+
let htmlForStream = "";
|
|
58
|
+
const cacheStream = new Transform({
|
|
59
|
+
write(chunk, _, callback) {
|
|
60
|
+
htmlForStream += chunk.toString();
|
|
61
|
+
this.push(chunk);
|
|
62
|
+
callback();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
cacheStream.on("close", () => onAfterRender(htmlForStream));
|
|
66
|
+
return source(cacheStream);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
35
69
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
cacheConfig
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
70
|
+
function saveHtmlIntoCache(html) {
|
|
71
|
+
return __async(this, null, function* () {
|
|
72
|
+
const { cacheConfig } = context;
|
|
73
|
+
if (html && cacheConfig) {
|
|
74
|
+
yield sprCache.set(cacheContext, html, cacheConfig);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
43
77
|
}
|
|
44
|
-
|
|
45
|
-
// no cache, render sync
|
|
46
78
|
if (!cacheFile) {
|
|
47
|
-
const renderResult =
|
|
79
|
+
const renderResult = yield renderFn(context);
|
|
48
80
|
return afterRender(renderResult, saveHtmlIntoCache);
|
|
49
81
|
}
|
|
50
|
-
const cacheHash = cacheFile
|
|
51
|
-
|
|
52
|
-
// completely expired
|
|
82
|
+
const cacheHash = cacheFile == null ? void 0 : cacheFile.hash;
|
|
53
83
|
if (cacheFile.isGarbage) {
|
|
54
|
-
const renderResult =
|
|
84
|
+
const renderResult = yield renderFn(context);
|
|
55
85
|
return afterRender(renderResult, saveHtmlIntoCache);
|
|
56
86
|
} else if (cacheFile.isStale) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
87
|
+
const render = withCoalescedInvoke(() => renderFn(context)).bind(
|
|
88
|
+
null,
|
|
89
|
+
namespaceHash("render", cacheFile.hash),
|
|
90
|
+
[]
|
|
91
|
+
);
|
|
92
|
+
render().then((res) => __async(void 0, null, function* () {
|
|
60
93
|
if (res.value && res.isOrigin) {
|
|
61
|
-
const {
|
|
62
|
-
cacheConfig
|
|
63
|
-
} = context;
|
|
94
|
+
const { cacheConfig } = context;
|
|
64
95
|
if (cacheConfig) {
|
|
65
|
-
afterRender(res.value,
|
|
96
|
+
afterRender(res.value, (html) => __async(void 0, null, function* () {
|
|
66
97
|
sprCache.set(cacheContext, html, cacheConfig);
|
|
67
|
-
});
|
|
98
|
+
}));
|
|
68
99
|
} else {
|
|
69
100
|
sprCache.del(cacheContext, cacheHash);
|
|
70
101
|
}
|
|
71
102
|
}
|
|
72
|
-
}).catch(e => {
|
|
103
|
+
})).catch((e) => {
|
|
73
104
|
sprCache.del(cacheContext, cacheHash);
|
|
74
105
|
ctx.error(ERROR_DIGEST.ERENDER, e);
|
|
75
106
|
});
|
|
76
107
|
}
|
|
77
|
-
ctx.res.setHeader(
|
|
108
|
+
ctx.res.setHeader("x-modern-spr", "1");
|
|
78
109
|
return cacheFile.content;
|
|
79
|
-
};
|
|
110
|
+
});
|
|
80
111
|
return doRender;
|
|
81
|
-
}
|
|
112
|
+
};
|
|
113
|
+
export {
|
|
114
|
+
cache_default as default
|
|
115
|
+
};
|
|
@@ -1,9 +1,32 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
1
21
|
import { LRUCaches } from "./lru";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
max
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
22
|
+
function createPageCaches(max) {
|
|
23
|
+
return __async(this, null, function* () {
|
|
24
|
+
const constructorOptions = { max };
|
|
25
|
+
const cacheInstance = new LRUCaches(constructorOptions);
|
|
26
|
+
yield cacheInstance.init();
|
|
27
|
+
return cacheInstance;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
createPageCaches
|
|
32
|
+
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export class LRUCaches {
|
|
1
|
+
import LRU from "lru-cache";
|
|
2
|
+
class LRUCaches {
|
|
4
3
|
constructor(options) {
|
|
5
|
-
_defineProperty(this, "caches", void 0);
|
|
6
|
-
_defineProperty(this, "max", void 0);
|
|
7
4
|
this.max = options.max;
|
|
8
5
|
this.caches = new LRU(this.max);
|
|
9
6
|
}
|
|
@@ -26,4 +23,7 @@ export class LRUCaches {
|
|
|
26
23
|
del(key) {
|
|
27
24
|
this.caches.del(key);
|
|
28
25
|
}
|
|
29
|
-
}
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
LRUCaches
|
|
29
|
+
};
|