@lcap/asl
Version:
NetEase Application Specific Language
92 lines • 3.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.clearLoadCache = exports.saveViewDetailCache = exports.savePageTreeCache = exports.saveInterfacesCache = void 0;
// 加载时的三个缓存,和 generator 的缓存有点像,所以暂时放在这里
const __1 = require("..");
const webFile_1 = require("../../service/webFile");
const preprocess_1 = require("../../service/common/preprocess");
/**
* 生成接口列表缓存
*/
function saveInterfacesCache(service) {
if (!__1.config.initialLoadCache)
return;
const timestamp = +new Date();
const json = [];
service.interfaces.forEach((item) => {
const itface = item.toJSON();
itface.serviceType = preprocess_1.ServiceType[itface.serviceType] || itface.serviceType;
itface._cacheTimestamp = timestamp;
// 目前 interface 下不会自动生成 logic
const logic = item.logic.toJSON();
logic.body = null;
logic.serviceType = preprocess_1.ServiceType[logic.serviceType];
itface.logic = logic;
json.push(itface);
});
return webFile_1.loadCacheService.setCache({
body: {
type: 'INTERFACE_LIST',
key: service.id,
data: JSON.stringify(json),
timestamp: +new Date(),
},
});
}
exports.saveInterfacesCache = saveInterfacesCache;
function savePageTreeCache(service) {
if (!__1.config.initialLoadCache)
return;
const timestamp = +new Date();
const json = [];
service.pages.forEach((item) => {
const page = item.toJSON();
page._cacheTimestamp = timestamp;
__1.utils.traverse((current) => {
if (current.node.level === 'view') {
const viewJson = current.node;
viewJson.$html = null;
viewJson.$def.logics.forEach((logic) => {
logic.body = null;
});
}
}, { node: page }, { mode: 'anyObject' });
json.push(page);
});
return webFile_1.loadCacheService.setCache({
body: {
type: 'PAGE_LIST',
key: service.id,
data: JSON.stringify(json),
timestamp: +new Date(),
},
});
}
exports.savePageTreeCache = savePageTreeCache;
function saveViewDetailCache(view) {
if (!__1.config.initialLoadCache)
return;
const timestamp = +new Date();
const json = view.toJSON('', ['children']);
delete json.children;
json._cacheTimestamp = timestamp;
return webFile_1.loadCacheService.setCache({
body: {
type: 'PAGE_DETAIL',
key: view.id,
data: JSON.stringify(json),
timestamp: +new Date(),
},
});
}
exports.saveViewDetailCache = saveViewDetailCache;
function clearLoadCache(type, key) {
return webFile_1.loadCacheService.clearCache({
query: {
type,
key,
},
});
}
exports.clearLoadCache = clearLoadCache;
//# sourceMappingURL=load.js.map