@modern-js/prod-server 2.42.2 → 2.44.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/dist/cjs/libs/{render/cache/page-caches/index.js → hook-api/afterRenderForStream.js} +12 -14
- package/dist/cjs/libs/hook-api/index.js +12 -0
- package/dist/cjs/libs/render/index.js +4 -14
- package/dist/cjs/libs/render/ssr.js +15 -4
- package/dist/cjs/libs/render/{cache/page-caches/lru.js → ssrCache/cacheMod.js} +21 -31
- package/dist/cjs/libs/render/ssrCache/index.js +81 -0
- package/dist/cjs/libs/render/ssrCache/manager.js +104 -0
- package/dist/cjs/libs/render/static.js +5 -5
- package/dist/cjs/server/index.js +2 -0
- package/dist/cjs/server/modernServer.js +2 -9
- package/dist/esm/libs/hook-api/afterRenderForStream.js +33 -0
- package/dist/esm/libs/hook-api/index.js +10 -0
- package/dist/esm/libs/render/index.js +4 -14
- package/dist/esm/libs/render/ssr.js +19 -5
- package/dist/esm/libs/render/ssrCache/cacheMod.js +33 -0
- package/dist/esm/libs/render/ssrCache/index.js +146 -0
- package/dist/esm/libs/render/ssrCache/manager.js +159 -0
- package/dist/esm/libs/render/static.js +5 -5
- package/dist/esm/server/index.js +14 -4
- package/dist/esm/server/modernServer.js +32 -42
- package/dist/esm-node/libs/hook-api/afterRenderForStream.js +10 -0
- package/dist/esm-node/libs/hook-api/index.js +11 -0
- package/dist/esm-node/libs/render/index.js +4 -14
- package/dist/esm-node/libs/render/ssr.js +15 -4
- package/dist/esm-node/libs/render/ssrCache/cacheMod.js +22 -0
- package/dist/esm-node/libs/render/ssrCache/index.js +57 -0
- package/dist/esm-node/libs/render/ssrCache/manager.js +80 -0
- package/dist/esm-node/libs/render/static.js +5 -5
- package/dist/esm-node/server/index.js +2 -0
- package/dist/esm-node/server/modernServer.js +2 -9
- package/dist/types/libs/context/index.d.ts +2 -0
- package/dist/types/libs/hook-api/afterRenderForStream.d.ts +4 -0
- package/dist/types/libs/hook-api/index.d.ts +2 -1
- package/dist/types/libs/preload/flushServerHeader.d.ts +2 -0
- package/dist/types/libs/proxy.d.ts +2 -0
- package/dist/types/libs/render/ssr.d.ts +5 -5
- package/dist/types/libs/render/ssrCache/cacheMod.d.ts +8 -0
- package/dist/types/libs/render/ssrCache/index.d.ts +7 -0
- package/dist/types/libs/render/ssrCache/manager.d.ts +14 -0
- package/dist/types/renderHtml.d.ts +2 -0
- package/dist/types/server/index.d.ts +2 -0
- package/dist/types/server/modernServer.d.ts +2 -3
- package/dist/types/type.d.ts +2 -0
- package/package.json +8 -11
- package/dist/cjs/libs/render/cache/__tests__/cache.fun.test.js +0 -95
- package/dist/cjs/libs/render/cache/__tests__/cache.test.js +0 -223
- package/dist/cjs/libs/render/cache/__tests__/cacheable.js +0 -93
- package/dist/cjs/libs/render/cache/__tests__/error-configuration.js +0 -71
- package/dist/cjs/libs/render/cache/__tests__/matched-cache.js +0 -173
- package/dist/cjs/libs/render/cache/index.js +0 -92
- package/dist/cjs/libs/render/cache/spr.js +0 -247
- package/dist/cjs/libs/render/cache/type.js +0 -16
- package/dist/cjs/libs/render/cache/util.js +0 -121
- package/dist/cjs/libs/render/reader.js +0 -131
- package/dist/esm/libs/render/cache/__tests__/cache.fun.test.js +0 -124
- package/dist/esm/libs/render/cache/__tests__/cache.test.js +0 -612
- package/dist/esm/libs/render/cache/__tests__/cacheable.js +0 -69
- package/dist/esm/libs/render/cache/__tests__/error-configuration.js +0 -47
- package/dist/esm/libs/render/cache/__tests__/matched-cache.js +0 -149
- package/dist/esm/libs/render/cache/index.js +0 -204
- package/dist/esm/libs/render/cache/page-caches/index.js +0 -34
- package/dist/esm/libs/render/cache/page-caches/lru.js +0 -57
- package/dist/esm/libs/render/cache/spr.js +0 -345
- package/dist/esm/libs/render/cache/type.js +0 -0
- package/dist/esm/libs/render/cache/util.js +0 -105
- package/dist/esm/libs/render/reader.js +0 -196
- package/dist/esm-node/libs/render/cache/__tests__/cache.fun.test.js +0 -72
- package/dist/esm-node/libs/render/cache/__tests__/cache.test.js +0 -222
- package/dist/esm-node/libs/render/cache/__tests__/cacheable.js +0 -69
- package/dist/esm-node/libs/render/cache/__tests__/error-configuration.js +0 -47
- package/dist/esm-node/libs/render/cache/__tests__/matched-cache.js +0 -149
- package/dist/esm-node/libs/render/cache/index.js +0 -72
- package/dist/esm-node/libs/render/cache/page-caches/index.js +0 -12
- package/dist/esm-node/libs/render/cache/page-caches/lru.js +0 -32
- package/dist/esm-node/libs/render/cache/spr.js +0 -212
- package/dist/esm-node/libs/render/cache/type.js +0 -0
- package/dist/esm-node/libs/render/cache/util.js +0 -80
- package/dist/esm-node/libs/render/reader.js +0 -93
- package/dist/types/libs/render/cache/__tests__/cache.fun.test.d.ts +0 -1
- package/dist/types/libs/render/cache/__tests__/cache.test.d.ts +0 -1
- package/dist/types/libs/render/cache/__tests__/cacheable.d.ts +0 -62
- package/dist/types/libs/render/cache/__tests__/error-configuration.d.ts +0 -28
- package/dist/types/libs/render/cache/__tests__/matched-cache.d.ts +0 -124
- package/dist/types/libs/render/cache/index.d.ts +0 -6
- package/dist/types/libs/render/cache/page-caches/index.d.ts +0 -2
- package/dist/types/libs/render/cache/page-caches/lru.d.ts +0 -15
- package/dist/types/libs/render/cache/spr.d.ts +0 -22
- package/dist/types/libs/render/cache/type.d.ts +0 -48
- package/dist/types/libs/render/cache/util.d.ts +0 -18
- package/dist/types/libs/render/reader.d.ts +0 -20
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
import crypto from "crypto";
|
|
3
|
-
import LRUCache from "lru-cache";
|
|
4
|
-
import { mime } from "@modern-js/utils";
|
|
5
|
-
import { cacheAddition, connectFactor, fname, maybeSync, namespaceHash, valueFactory, withCoalescedInvoke } from "./util";
|
|
6
|
-
import { createPageCaches } from "./page-caches";
|
|
7
|
-
const MAX_CACHE_EACH_REQ = Number(process.env.ROUTE_CACHE_LIMIT) || 10;
|
|
8
|
-
const MAX_SIZE_EACH_CLUSTER = Number(process.env.CLUSTER_CACHE_LIMIT) || 100;
|
|
9
|
-
const BASE_LEVEL = 0;
|
|
10
|
-
const QUERY_LEVEL = 1;
|
|
11
|
-
const HEADER_LEVEL = 2;
|
|
12
|
-
const QUERY_HEADER_LEVEL = 3;
|
|
13
|
-
class CacheManager {
|
|
14
|
-
md5(content) {
|
|
15
|
-
const md5 = crypto.createHash("md5");
|
|
16
|
-
return md5.update(content).digest("hex");
|
|
17
|
-
}
|
|
18
|
-
generateRequestKey(context) {
|
|
19
|
-
const { pathname, entry } = context;
|
|
20
|
-
return this.md5(`${pathname}_${entry}`);
|
|
21
|
-
}
|
|
22
|
-
replaceValue(value, matcher) {
|
|
23
|
-
let final = value;
|
|
24
|
-
Object.keys(matcher).some((replacer) => {
|
|
25
|
-
const reg = new RegExp(matcher[replacer]);
|
|
26
|
-
if (reg.test(value)) {
|
|
27
|
-
final = replacer;
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
});
|
|
32
|
-
return final;
|
|
33
|
-
}
|
|
34
|
-
factor(keys, obj, matches = {}) {
|
|
35
|
-
keys.sort();
|
|
36
|
-
const getValue = valueFactory(obj);
|
|
37
|
-
const factorAry = keys.reduce((ary, key) => {
|
|
38
|
-
let value = getValue(key) || "";
|
|
39
|
-
const matcher = matches[key];
|
|
40
|
-
if (matcher) {
|
|
41
|
-
value = this.replaceValue(value, matcher);
|
|
42
|
-
}
|
|
43
|
-
return ary.concat([
|
|
44
|
-
key,
|
|
45
|
-
value
|
|
46
|
-
]);
|
|
47
|
-
}, []);
|
|
48
|
-
return factorAry.join(",");
|
|
49
|
-
}
|
|
50
|
-
queryFactor(context, data) {
|
|
51
|
-
var _data_includes, _data_matches;
|
|
52
|
-
const queryKeys = (_data_includes = data.includes) === null || _data_includes === void 0 ? void 0 : _data_includes.query;
|
|
53
|
-
const queryMatches = (_data_matches = data.matches) === null || _data_matches === void 0 ? void 0 : _data_matches.query;
|
|
54
|
-
if (!queryKeys || queryKeys.length === 0) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
const requestQuery = context.query;
|
|
58
|
-
const queryFactor = this.factor(queryKeys, requestQuery, queryMatches);
|
|
59
|
-
return queryFactor;
|
|
60
|
-
}
|
|
61
|
-
headerFactor(context, data) {
|
|
62
|
-
var _data_includes, _data_matches;
|
|
63
|
-
const headerKeys = (_data_includes = data.includes) === null || _data_includes === void 0 ? void 0 : _data_includes.header;
|
|
64
|
-
const headerMatches = (_data_matches = data.matches) === null || _data_matches === void 0 ? void 0 : _data_matches.header;
|
|
65
|
-
if (!headerKeys || headerKeys.length === 0) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
const requestHeader = context.headers;
|
|
69
|
-
const headerFactor = this.factor(headerKeys, requestHeader, headerMatches);
|
|
70
|
-
return headerFactor;
|
|
71
|
-
}
|
|
72
|
-
async best(context, cacheKey, data) {
|
|
73
|
-
const { level } = data;
|
|
74
|
-
const cacheHash = this.find[fname(level)](context, cacheKey, data);
|
|
75
|
-
if (!cacheHash) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
return data.caches.get(cacheHash);
|
|
79
|
-
}
|
|
80
|
-
createCacheContent(config, caches) {
|
|
81
|
-
return {
|
|
82
|
-
level: config.level,
|
|
83
|
-
interval: config.interval,
|
|
84
|
-
includes: config.includes || null,
|
|
85
|
-
limit: config.staleLimit,
|
|
86
|
-
matches: config.matches || null,
|
|
87
|
-
caches
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
async get(context) {
|
|
91
|
-
const cacheKey = this.generateRequestKey(context);
|
|
92
|
-
const data = this.cache.get(cacheKey);
|
|
93
|
-
if (!data) {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
const dest = await this.best(context, cacheKey, data);
|
|
97
|
-
if (!dest) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
const { expireTime, limitTime, html, cacheHash } = dest;
|
|
101
|
-
const isStale = Date.now() - expireTime > 0;
|
|
102
|
-
const isGarbage = limitTime ? Date.now() - limitTime > 0 : false;
|
|
103
|
-
return {
|
|
104
|
-
content: html || "",
|
|
105
|
-
contentType: mime.contentType("html"),
|
|
106
|
-
isStale,
|
|
107
|
-
isGarbage,
|
|
108
|
-
hash: cacheHash
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
async set(context, html, cacheConfig, sync = false) {
|
|
112
|
-
if (!cacheConfig) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
const cacheKey = this.generateRequestKey(context);
|
|
116
|
-
let data = this.cache.get(cacheKey);
|
|
117
|
-
if (!data) {
|
|
118
|
-
const caches = await createPageCaches(MAX_CACHE_EACH_REQ);
|
|
119
|
-
data = this.createCacheContent(cacheConfig, caches);
|
|
120
|
-
}
|
|
121
|
-
const cacheHash = this.find[fname(cacheConfig.level)](context, cacheKey, data);
|
|
122
|
-
if (!cacheHash) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
const cacheSyncOrAsync = async () => {
|
|
126
|
-
const next = data;
|
|
127
|
-
const limit = cacheConfig.staleLimit;
|
|
128
|
-
const storeHTML = cacheAddition(html, cacheHash);
|
|
129
|
-
const size = storeHTML.length;
|
|
130
|
-
await next.caches.set(cacheHash, {
|
|
131
|
-
expireTime: Date.now() + cacheConfig.interval * 1e3,
|
|
132
|
-
limitTime: typeof limit === "number" ? Date.now() + limit * 1e3 : null,
|
|
133
|
-
cacheHash,
|
|
134
|
-
html: storeHTML,
|
|
135
|
-
size
|
|
136
|
-
});
|
|
137
|
-
this.cache.set(cacheKey, next);
|
|
138
|
-
return true;
|
|
139
|
-
};
|
|
140
|
-
const doCache = withCoalescedInvoke(cacheSyncOrAsync).bind(null, namespaceHash("stream", cacheHash), []);
|
|
141
|
-
return maybeSync(doCache)(sync);
|
|
142
|
-
}
|
|
143
|
-
async del(context, cacheHash) {
|
|
144
|
-
const cacheKey = this.generateRequestKey(context);
|
|
145
|
-
const data = this.cache.get(cacheKey);
|
|
146
|
-
data === null || data === void 0 ? void 0 : data.caches.del(cacheHash);
|
|
147
|
-
}
|
|
148
|
-
constructor(cacheOptions) {
|
|
149
|
-
_define_property(this, "cache", void 0);
|
|
150
|
-
_define_property(this, "cacheOptions", void 0);
|
|
151
|
-
_define_property(this, "find", (() => {
|
|
152
|
-
{
|
|
153
|
-
const _this = this;
|
|
154
|
-
return {
|
|
155
|
-
[fname(BASE_LEVEL)](context, cacheKey) {
|
|
156
|
-
return _this.md5(cacheKey);
|
|
157
|
-
},
|
|
158
|
-
[fname(QUERY_LEVEL)](context, cacheKey, data) {
|
|
159
|
-
const queryFactor = _this.queryFactor(context, data);
|
|
160
|
-
if (!queryFactor) {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
return _this.md5(connectFactor(cacheKey, queryFactor));
|
|
164
|
-
},
|
|
165
|
-
[fname(HEADER_LEVEL)](context, cacheKey, data) {
|
|
166
|
-
const headerFactor = _this.headerFactor(context, data);
|
|
167
|
-
if (!headerFactor) {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
return _this.md5(connectFactor(cacheKey, headerFactor));
|
|
171
|
-
},
|
|
172
|
-
[fname(QUERY_HEADER_LEVEL)](context, cacheKey, data) {
|
|
173
|
-
const queryFactor = _this.queryFactor(context, data);
|
|
174
|
-
const headerFactor = _this.headerFactor(context, data);
|
|
175
|
-
if (!queryFactor || !headerFactor) {
|
|
176
|
-
return null;
|
|
177
|
-
}
|
|
178
|
-
return _this.md5(connectFactor(cacheKey, headerFactor, queryFactor));
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
})());
|
|
183
|
-
this.cacheOptions = cacheOptions;
|
|
184
|
-
this.cache = new LRUCache({
|
|
185
|
-
max: Math.min(MAX_SIZE_EACH_CLUSTER, 600) * 1024 * 1024,
|
|
186
|
-
length(n) {
|
|
187
|
-
const len = n.caches.keys().reduce((total, cur) => {
|
|
188
|
-
var _n_caches_peek;
|
|
189
|
-
return total + (((_n_caches_peek = n.caches.peek(cur)) === null || _n_caches_peek === void 0 ? void 0 : _n_caches_peek.size) || 0);
|
|
190
|
-
}, 1);
|
|
191
|
-
return len;
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
let manager;
|
|
197
|
-
function createCache() {
|
|
198
|
-
if (manager) {
|
|
199
|
-
return manager;
|
|
200
|
-
}
|
|
201
|
-
manager = new CacheManager({
|
|
202
|
-
max: 0
|
|
203
|
-
});
|
|
204
|
-
return manager;
|
|
205
|
-
}
|
|
206
|
-
function destroyCache() {
|
|
207
|
-
manager = null;
|
|
208
|
-
}
|
|
209
|
-
export {
|
|
210
|
-
createCache,
|
|
211
|
-
destroyCache
|
|
212
|
-
};
|
|
File without changes
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import url from "url";
|
|
2
|
-
function namespaceHash(namespace, hash) {
|
|
3
|
-
return `${namespace}/${hash}`;
|
|
4
|
-
}
|
|
5
|
-
function fname(lv) {
|
|
6
|
-
return `f${lv}`;
|
|
7
|
-
}
|
|
8
|
-
function connectFactor(...args) {
|
|
9
|
-
return args.join("-");
|
|
10
|
-
}
|
|
11
|
-
function valueFactory(obj) {
|
|
12
|
-
if (obj instanceof url.URLSearchParams) {
|
|
13
|
-
return function(key) {
|
|
14
|
-
return obj.get(key);
|
|
15
|
-
};
|
|
16
|
-
} else {
|
|
17
|
-
return function(key) {
|
|
18
|
-
const value = obj[key];
|
|
19
|
-
if (Array.isArray(value)) {
|
|
20
|
-
return value.join(",");
|
|
21
|
-
}
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function getTime([s, ns]) {
|
|
27
|
-
return Math.floor(s * 1e3 + ns / 1e6);
|
|
28
|
-
}
|
|
29
|
-
const RE_START_IN_HEAD = /<head>/;
|
|
30
|
-
function cacheAddition(html, hash) {
|
|
31
|
-
const additionHtml = html.replace(RE_START_IN_HEAD, `<head><meta name="x-moden-spr" content="${hash}">`);
|
|
32
|
-
return additionHtml;
|
|
33
|
-
}
|
|
34
|
-
const globalInvokeCache = /* @__PURE__ */ new Map();
|
|
35
|
-
function withCoalescedInvoke(func) {
|
|
36
|
-
return async function(key, args) {
|
|
37
|
-
const entry = globalInvokeCache.get(key);
|
|
38
|
-
if (entry) {
|
|
39
|
-
return entry.then((res) => ({
|
|
40
|
-
isOrigin: false,
|
|
41
|
-
value: res.value
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
function __wrapper() {
|
|
45
|
-
return func(...args);
|
|
46
|
-
}
|
|
47
|
-
const future = __wrapper().then((res) => {
|
|
48
|
-
globalInvokeCache.delete(key);
|
|
49
|
-
return {
|
|
50
|
-
isOrigin: true,
|
|
51
|
-
value: res
|
|
52
|
-
};
|
|
53
|
-
}).catch((err) => {
|
|
54
|
-
globalInvokeCache.delete(key);
|
|
55
|
-
throw err;
|
|
56
|
-
});
|
|
57
|
-
globalInvokeCache.set(key, future);
|
|
58
|
-
return future;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function maybeSync(fn) {
|
|
62
|
-
return (sync) => {
|
|
63
|
-
if (sync) {
|
|
64
|
-
return fn();
|
|
65
|
-
} else {
|
|
66
|
-
fn();
|
|
67
|
-
return Promise.resolve();
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
export {
|
|
72
|
-
cacheAddition,
|
|
73
|
-
connectFactor,
|
|
74
|
-
fname,
|
|
75
|
-
getTime,
|
|
76
|
-
maybeSync,
|
|
77
|
-
namespaceHash,
|
|
78
|
-
valueFactory,
|
|
79
|
-
withCoalescedInvoke
|
|
80
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
import { fs as extraFS } from "@modern-js/utils";
|
|
3
|
-
import LRU from "lru-cache";
|
|
4
|
-
const Byte = 1;
|
|
5
|
-
const KB = 1024 * Byte;
|
|
6
|
-
const MB = 1024 * KB;
|
|
7
|
-
const getContentLength = (cache) => cache.content.length;
|
|
8
|
-
const createCacheItem = async (content, mtime) => {
|
|
9
|
-
return {
|
|
10
|
-
content,
|
|
11
|
-
mtime
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
class LruReader {
|
|
15
|
-
init(fs) {
|
|
16
|
-
this.fs = fs || extraFS;
|
|
17
|
-
}
|
|
18
|
-
close() {
|
|
19
|
-
}
|
|
20
|
-
async read(filepath) {
|
|
21
|
-
const { fs } = this;
|
|
22
|
-
if (this.cache.has(filepath)) {
|
|
23
|
-
const { content: content2 } = this.cache.get(filepath);
|
|
24
|
-
return {
|
|
25
|
-
content: content2
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
if (!fs.existsSync(filepath)) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
const stat = fs.statSync(filepath);
|
|
32
|
-
if (stat.isDirectory()) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
if (stat.size > 20 * MB) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
const content = await fs.promises.readFile(filepath);
|
|
39
|
-
const item = await createCacheItem(content, stat.mtime);
|
|
40
|
-
this.cache.set(filepath, item);
|
|
41
|
-
return item;
|
|
42
|
-
}
|
|
43
|
-
update() {
|
|
44
|
-
const { cache, fs } = this;
|
|
45
|
-
const files = cache.keys();
|
|
46
|
-
for (const filepath of files) {
|
|
47
|
-
if (!fs.existsSync(filepath)) {
|
|
48
|
-
cache.del(filepath);
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
const item = cache.get(filepath);
|
|
52
|
-
const stat = fs.statSync(filepath);
|
|
53
|
-
const { mtime } = stat;
|
|
54
|
-
if (item.mtime < mtime) {
|
|
55
|
-
cache.del(filepath);
|
|
56
|
-
}
|
|
57
|
-
} catch (e) {
|
|
58
|
-
cache.del(filepath);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
constructor() {
|
|
63
|
-
_define_property(this, "cache", void 0);
|
|
64
|
-
_define_property(this, "fs", void 0);
|
|
65
|
-
this.cache = new LRU({
|
|
66
|
-
max: 256 * MB,
|
|
67
|
-
length: getContentLength,
|
|
68
|
-
maxAge: 5 * 60 * 5e3
|
|
69
|
-
});
|
|
70
|
-
this.fs = extraFS;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const reader = new LruReader();
|
|
74
|
-
const readFile = async (filepath) => {
|
|
75
|
-
const file = await reader.read(filepath);
|
|
76
|
-
return file === null || file === void 0 ? void 0 : file.content;
|
|
77
|
-
};
|
|
78
|
-
const updateFile = () => {
|
|
79
|
-
reader.update();
|
|
80
|
-
};
|
|
81
|
-
const init = (fs) => {
|
|
82
|
-
reader.init(fs);
|
|
83
|
-
};
|
|
84
|
-
const close = () => {
|
|
85
|
-
reader.close();
|
|
86
|
-
};
|
|
87
|
-
export {
|
|
88
|
-
LruReader,
|
|
89
|
-
close,
|
|
90
|
-
init,
|
|
91
|
-
readFile,
|
|
92
|
-
updateFile
|
|
93
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export declare const cacheabelAry: ({
|
|
2
|
-
requestOpt: {
|
|
3
|
-
url: string;
|
|
4
|
-
query?: undefined;
|
|
5
|
-
headers?: undefined;
|
|
6
|
-
};
|
|
7
|
-
cacheConfig: {
|
|
8
|
-
level?: undefined;
|
|
9
|
-
includes?: undefined;
|
|
10
|
-
};
|
|
11
|
-
content: string;
|
|
12
|
-
} | {
|
|
13
|
-
requestOpt: {
|
|
14
|
-
url: string;
|
|
15
|
-
query: {
|
|
16
|
-
name: string;
|
|
17
|
-
};
|
|
18
|
-
headers?: undefined;
|
|
19
|
-
};
|
|
20
|
-
cacheConfig: {
|
|
21
|
-
level: number;
|
|
22
|
-
includes: {
|
|
23
|
-
query: string[];
|
|
24
|
-
header?: undefined;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
content: string;
|
|
28
|
-
} | {
|
|
29
|
-
requestOpt: {
|
|
30
|
-
url: string;
|
|
31
|
-
headers: {
|
|
32
|
-
age: string;
|
|
33
|
-
};
|
|
34
|
-
query?: undefined;
|
|
35
|
-
};
|
|
36
|
-
cacheConfig: {
|
|
37
|
-
level: number;
|
|
38
|
-
includes: {
|
|
39
|
-
header: string[];
|
|
40
|
-
query?: undefined;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
content: string;
|
|
44
|
-
} | {
|
|
45
|
-
requestOpt: {
|
|
46
|
-
url: string;
|
|
47
|
-
query: {
|
|
48
|
-
name: string;
|
|
49
|
-
};
|
|
50
|
-
headers: {
|
|
51
|
-
age: string;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
cacheConfig: {
|
|
55
|
-
level: number;
|
|
56
|
-
includes: {
|
|
57
|
-
query: string[];
|
|
58
|
-
header: string[];
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
content: string;
|
|
62
|
-
})[];
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export declare const errorConfiguration: ({
|
|
2
|
-
level: number;
|
|
3
|
-
includes?: undefined;
|
|
4
|
-
} | {
|
|
5
|
-
level: number;
|
|
6
|
-
includes: {
|
|
7
|
-
query?: undefined;
|
|
8
|
-
header?: undefined;
|
|
9
|
-
};
|
|
10
|
-
} | {
|
|
11
|
-
level: number;
|
|
12
|
-
includes: {
|
|
13
|
-
query: never[];
|
|
14
|
-
header?: undefined;
|
|
15
|
-
};
|
|
16
|
-
} | {
|
|
17
|
-
level: number;
|
|
18
|
-
includes: {
|
|
19
|
-
header: never[];
|
|
20
|
-
query?: undefined;
|
|
21
|
-
};
|
|
22
|
-
} | {
|
|
23
|
-
level: number;
|
|
24
|
-
includes: {
|
|
25
|
-
query: never[];
|
|
26
|
-
header: never[];
|
|
27
|
-
};
|
|
28
|
-
})[];
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
export declare const matchedCacheableAry: (({
|
|
2
|
-
requestOpt: {
|
|
3
|
-
url: string;
|
|
4
|
-
headers: {};
|
|
5
|
-
query: {
|
|
6
|
-
name: string;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
cacheConfig: {
|
|
10
|
-
level: number;
|
|
11
|
-
includes: {
|
|
12
|
-
query: string[];
|
|
13
|
-
};
|
|
14
|
-
matches: {
|
|
15
|
-
query: {
|
|
16
|
-
name: {
|
|
17
|
-
weixin: string;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
content: string;
|
|
23
|
-
url?: undefined;
|
|
24
|
-
headers?: undefined;
|
|
25
|
-
query?: undefined;
|
|
26
|
-
} | {
|
|
27
|
-
url: string;
|
|
28
|
-
headers: {};
|
|
29
|
-
query: {
|
|
30
|
-
name: string;
|
|
31
|
-
};
|
|
32
|
-
requestOpt?: undefined;
|
|
33
|
-
cacheConfig?: undefined;
|
|
34
|
-
content?: undefined;
|
|
35
|
-
})[] | ({
|
|
36
|
-
requestOpt: {
|
|
37
|
-
url: string;
|
|
38
|
-
query: {};
|
|
39
|
-
headers: {
|
|
40
|
-
age: string;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
cacheConfig: {
|
|
44
|
-
level: number;
|
|
45
|
-
includes: {
|
|
46
|
-
header: string[];
|
|
47
|
-
};
|
|
48
|
-
matches: {
|
|
49
|
-
header: {
|
|
50
|
-
age: {
|
|
51
|
-
one: string;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
content: string;
|
|
57
|
-
url?: undefined;
|
|
58
|
-
query?: undefined;
|
|
59
|
-
headers?: undefined;
|
|
60
|
-
} | {
|
|
61
|
-
url: string;
|
|
62
|
-
query: {};
|
|
63
|
-
headers: {
|
|
64
|
-
age: string;
|
|
65
|
-
};
|
|
66
|
-
requestOpt?: undefined;
|
|
67
|
-
cacheConfig?: undefined;
|
|
68
|
-
content?: undefined;
|
|
69
|
-
})[] | ({
|
|
70
|
-
requestOpt: {
|
|
71
|
-
url: string;
|
|
72
|
-
headers: {
|
|
73
|
-
age: string;
|
|
74
|
-
};
|
|
75
|
-
query: {
|
|
76
|
-
name: string;
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
cacheConfig: {
|
|
80
|
-
level: number;
|
|
81
|
-
includes: {
|
|
82
|
-
query: string[];
|
|
83
|
-
header: string[];
|
|
84
|
-
};
|
|
85
|
-
matches: {
|
|
86
|
-
query: {
|
|
87
|
-
name: {
|
|
88
|
-
weixin: string;
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
header: {
|
|
92
|
-
age: {
|
|
93
|
-
one: string;
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
content: string;
|
|
99
|
-
url?: undefined;
|
|
100
|
-
query?: undefined;
|
|
101
|
-
headers?: undefined;
|
|
102
|
-
} | {
|
|
103
|
-
url: string;
|
|
104
|
-
query: {
|
|
105
|
-
name: string;
|
|
106
|
-
};
|
|
107
|
-
headers: {
|
|
108
|
-
age: string;
|
|
109
|
-
};
|
|
110
|
-
requestOpt?: undefined;
|
|
111
|
-
cacheConfig?: undefined;
|
|
112
|
-
content?: undefined;
|
|
113
|
-
} | {
|
|
114
|
-
url: string;
|
|
115
|
-
query: {
|
|
116
|
-
name: string;
|
|
117
|
-
};
|
|
118
|
-
headers: {
|
|
119
|
-
age?: undefined;
|
|
120
|
-
};
|
|
121
|
-
requestOpt?: undefined;
|
|
122
|
-
cacheConfig?: undefined;
|
|
123
|
-
content?: undefined;
|
|
124
|
-
})[])[];
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Readable } from 'stream';
|
|
3
|
-
import type { ModernServerContext } from '@modern-js/types';
|
|
4
|
-
import { RenderFunction, SSRServerContext } from '../type';
|
|
5
|
-
declare const _default: (renderFn: RenderFunction, ctx: ModernServerContext) => (context: SSRServerContext) => Promise<string | Readable>;
|
|
6
|
-
export default _default;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import LRU from 'lru-cache';
|
|
2
|
-
import { PageCache, PageCachesInterface } from '../type';
|
|
3
|
-
export declare class LRUCaches implements PageCachesInterface {
|
|
4
|
-
caches: LRU<string, PageCache>;
|
|
5
|
-
private readonly max;
|
|
6
|
-
constructor(options: {
|
|
7
|
-
max: number;
|
|
8
|
-
});
|
|
9
|
-
init(): Promise<void>;
|
|
10
|
-
keys(): string[];
|
|
11
|
-
get(key: string): Promise<PageCache | null>;
|
|
12
|
-
peek(key: string): PageCache | null;
|
|
13
|
-
set(key: string, cache: PageCache): Promise<void>;
|
|
14
|
-
del(key: string): void;
|
|
15
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import LRUCache from 'lru-cache';
|
|
2
|
-
import { CacheContent, CacheManagerOptions, CacheResult, CacheContext, CacheConfig } from './type';
|
|
3
|
-
declare class CacheManager {
|
|
4
|
-
cache: LRUCache<string, CacheContent>;
|
|
5
|
-
cacheOptions: CacheManagerOptions;
|
|
6
|
-
constructor(cacheOptions: CacheManagerOptions);
|
|
7
|
-
private md5;
|
|
8
|
-
private generateRequestKey;
|
|
9
|
-
private replaceValue;
|
|
10
|
-
private factor;
|
|
11
|
-
private queryFactor;
|
|
12
|
-
private headerFactor;
|
|
13
|
-
private readonly find;
|
|
14
|
-
private best;
|
|
15
|
-
private createCacheContent;
|
|
16
|
-
get(context: CacheContext): Promise<CacheResult | null>;
|
|
17
|
-
set(context: CacheContext, html: string, cacheConfig: CacheConfig, sync?: boolean): Promise<any>;
|
|
18
|
-
del(context: CacheContext, cacheHash: string): Promise<void>;
|
|
19
|
-
}
|
|
20
|
-
export declare function createCache(): CacheManager;
|
|
21
|
-
export declare function destroyCache(): void;
|
|
22
|
-
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IncomingHttpHeaders } from 'http';
|
|
3
|
-
import { RenderResult } from '../../../type';
|
|
4
|
-
export type { CacheConfig } from '../type';
|
|
5
|
-
export type CacheContent = {
|
|
6
|
-
level: number;
|
|
7
|
-
includes: {
|
|
8
|
-
header?: string[];
|
|
9
|
-
query?: string[];
|
|
10
|
-
} | null;
|
|
11
|
-
matches?: {
|
|
12
|
-
header?: Record<string, Record<string, string>>;
|
|
13
|
-
query?: Record<string, Record<string, string>>;
|
|
14
|
-
} | null;
|
|
15
|
-
interval: number;
|
|
16
|
-
limit: number | boolean;
|
|
17
|
-
caches: PageCachesInterface;
|
|
18
|
-
};
|
|
19
|
-
export interface PageCachesInterface {
|
|
20
|
-
caches: any;
|
|
21
|
-
init: () => void;
|
|
22
|
-
get: (key: string) => Promise<PageCache | null>;
|
|
23
|
-
peek: (key: string) => PageCache | null;
|
|
24
|
-
set: (key: string, cache: PageCache) => Promise<void>;
|
|
25
|
-
del: (key: string) => void;
|
|
26
|
-
keys: () => string[];
|
|
27
|
-
}
|
|
28
|
-
export type PageCache = {
|
|
29
|
-
html: string;
|
|
30
|
-
expireTime: number;
|
|
31
|
-
limitTime: number | null;
|
|
32
|
-
cacheHash: string;
|
|
33
|
-
size: number;
|
|
34
|
-
};
|
|
35
|
-
export type CacheManagerOptions = {
|
|
36
|
-
max: number;
|
|
37
|
-
};
|
|
38
|
-
export interface CacheResult extends RenderResult {
|
|
39
|
-
isStale: boolean;
|
|
40
|
-
isGarbage: boolean;
|
|
41
|
-
hash: string;
|
|
42
|
-
}
|
|
43
|
-
export type CacheContext = {
|
|
44
|
-
entry: string;
|
|
45
|
-
pathname: string;
|
|
46
|
-
query: Record<string, string>;
|
|
47
|
-
headers: IncomingHttpHeaders;
|
|
48
|
-
};
|