midway-fatcms 0.0.1-beta.67 → 0.0.1-beta.68
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/config/config.default.js +4 -1
- package/dist/controller/gateway/PublicApiController.js +3 -11
- package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +4 -4
- package/dist/models/SystemEntities.d.ts +0 -22
- package/dist/models/SystemEntities.js +1 -14
- package/dist/models/bizmodels.d.ts +19 -1
- package/dist/models/bizmodels.js +15 -1
- package/dist/service/EnumInfoService.js +3 -9
- package/dist/service/UserSessionService.js +4 -7
- package/dist/service/base/cache/CacheServiceFactory.d.ts +3 -5
- package/dist/service/base/cache/CacheServiceFactory.js +24 -13
- package/dist/service/base/cache/CtxCache.d.ts +2 -3
- package/dist/service/base/cache/CtxCache.js +1 -2
- package/dist/service/base/cache/DiskCache.d.ts +6 -11
- package/dist/service/base/cache/DiskCache.js +10 -17
- package/dist/service/base/cache/MemoryCache.d.ts +3 -9
- package/dist/service/base/cache/MemoryCache.js +6 -14
- package/dist/service/base/cache/RedisCache.d.ts +3 -9
- package/dist/service/base/cache/RedisCache.js +6 -14
- package/dist/service/crudstd/CrudStdService.js +3 -11
- package/dist/service/curd/CurdMixByAccountService.d.ts +4 -0
- package/dist/service/curd/CurdMixByAccountService.js +50 -12
- package/dist/service/curd/CurdMixByDictService.js +4 -8
- package/dist/service/curd/CurdMixByLinkToCustomService.js +2 -7
- package/dist/service/curd/CurdMixBySysConfigService.js +4 -8
- package/dist/service/curd/CurdMixByWorkbenchService.js +3 -9
- package/package.json +1 -1
- package/src/config/config.default.ts +4 -1
- package/src/controller/gateway/PublicApiController.ts +2 -14
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +7 -5
- package/src/models/SystemEntities.ts +1 -30
- package/src/models/WorkbenchInfoTools.ts +3 -2
- package/src/models/bizmodels.ts +25 -3
- package/src/service/EnumInfoService.ts +12 -18
- package/src/service/UserSessionService.ts +13 -18
- package/src/service/base/cache/CacheServiceFactory.ts +47 -38
- package/src/service/base/cache/CtxCache.ts +2 -4
- package/src/service/base/cache/DiskCache.ts +15 -20
- package/src/service/base/cache/MemoryCache.ts +8 -14
- package/src/service/base/cache/RedisCache.ts +8 -15
- package/src/service/crudstd/CrudStdService.ts +19 -31
- package/src/service/curd/CurdMixByAccountService.ts +62 -14
- package/src/service/curd/CurdMixByDictService.ts +6 -11
- package/src/service/curd/CurdMixByLinkToCustomService.ts +1 -8
- package/src/service/curd/CurdMixBySysConfigService.ts +8 -15
- package/src/service/curd/CurdMixByWorkbenchService.ts +3 -10
|
@@ -153,7 +153,10 @@ exports.default = (appInfo) => {
|
|
|
153
153
|
*/
|
|
154
154
|
fatcmsCache: {
|
|
155
155
|
diskCacheDir: (0, path_1.join)((0, os_1.tmpdir)(), 'fatcms-disk-cache'),
|
|
156
|
-
|
|
156
|
+
cacheConfig: {
|
|
157
|
+
UserSessionBySessionId: { cacheLevel: 'REDIS', cacheSecond: 3600 * 24 * 30 },
|
|
158
|
+
UserSessionByAsyncTaskId: { cacheLevel: 'REDIS', cacheSecond: 3600 },
|
|
159
|
+
}
|
|
157
160
|
},
|
|
158
161
|
// 用户会话保持时间,单位秒
|
|
159
162
|
fatcmsUserSessionKeepTimeSecond: 3600 * 24 * 30,
|
|
@@ -23,9 +23,7 @@ const SystemPerm_1 = require("../../models/SystemPerm");
|
|
|
23
23
|
const keys_2 = require("../../libs/crud-pro/models/keys");
|
|
24
24
|
const CacheServiceFactory_1 = require("../../service/base/cache/CacheServiceFactory");
|
|
25
25
|
const md5 = require("md5");
|
|
26
|
-
const
|
|
27
|
-
const DEFAULT_CACHE_LEVEL = SystemEntities_1.CacheLevelEnum.MEMORY;
|
|
28
|
-
const DEFAULT_CACHE_SECOND = 60 * 5;
|
|
26
|
+
const bizmodels_1 = require("../../models/bizmodels");
|
|
29
27
|
/**
|
|
30
28
|
* 公开的API,无需鉴权,所有人可以直接访问
|
|
31
29
|
*/
|
|
@@ -54,12 +52,9 @@ let PublicApiController = class PublicApiController extends BaseApiController_1.
|
|
|
54
52
|
if (!workbenchMenuCode) {
|
|
55
53
|
return common_dto_1.CommonResult.errorRes('param workbenchMenuCode is null');
|
|
56
54
|
}
|
|
57
|
-
const { publicApiMenuCacheLevel, publicApiMenuCacheSecond } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
|
|
58
55
|
const mapResult = await this.cacheServiceFactory.getJsonObjectCache({
|
|
59
|
-
cacheLevel: publicApiMenuCacheLevel || DEFAULT_CACHE_LEVEL,
|
|
60
56
|
cacheKey: "" + workbenchMenuCode,
|
|
61
|
-
|
|
62
|
-
cacheName: SystemEntities_1.CacheNameEnum.GetWorkbenchMenu,
|
|
57
|
+
cacheName: bizmodels_1.CacheNameEnum.GetWorkbenchMenu,
|
|
63
58
|
getter: async () => {
|
|
64
59
|
const workbenchMenuCodeStr = '' + workbenchMenuCode;
|
|
65
60
|
const workbenchMenuCodeArray = workbenchMenuCodeStr.split(',');
|
|
@@ -110,14 +105,11 @@ let PublicApiController = class PublicApiController extends BaseApiController_1.
|
|
|
110
105
|
}
|
|
111
106
|
return null;
|
|
112
107
|
};
|
|
113
|
-
const { publicApiNavPageInfoCacheLevel, publicApiNavPageInfoCacheSecond } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
|
|
114
108
|
const getOne = async (condition, tableName, key) => {
|
|
115
109
|
const cacheKey = md5(tableName + ':' + JSON.stringify(condition) + ":" + key);
|
|
116
110
|
const oneData = await this.cacheServiceFactory.getJsonObjectCache({
|
|
117
|
-
cacheLevel: publicApiNavPageInfoCacheLevel || DEFAULT_CACHE_LEVEL,
|
|
118
|
-
cacheSecond: publicApiNavPageInfoCacheSecond || DEFAULT_CACHE_SECOND,
|
|
119
111
|
cacheKey,
|
|
120
|
-
cacheName:
|
|
112
|
+
cacheName: bizmodels_1.CacheNameEnum.GetNavPageInfo,
|
|
121
113
|
getter: async () => {
|
|
122
114
|
return await getOneImpl(condition, tableName);
|
|
123
115
|
},
|
|
@@ -26,7 +26,7 @@ class CrudProExecuteSqlService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
async executeSqlCfgModel(sqlCfgModel) {
|
|
29
|
-
this.logger.info('
|
|
29
|
+
this.logger.info('[CrudProExecuteSqlService] executeSqlCfgModel_before', sqlCfgModel.executeSql, sqlCfgModel.executeSqlArgs);
|
|
30
30
|
const exeCtx = this.getExecuteContext();
|
|
31
31
|
const connection = await this.getTxConnectionBySqlCfg(sqlCfgModel);
|
|
32
32
|
const executeSqlArgs = this.handleExecuteSqlArgsByResModel(exeCtx, sqlCfgModel.executeSqlArgs || []);
|
|
@@ -35,22 +35,22 @@ class CrudProExecuteSqlService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
35
35
|
// import { PoolClient } from 'pg';
|
|
36
36
|
const pgClient = connection;
|
|
37
37
|
const pgSql = (0, convertPgSql_1.replaceQuestionMarks)(sqlCfgModel.executeSql);
|
|
38
|
-
this.logger.debug('[CrudProExecuteSqlService]executeSqlCfgModel_postgres', pgSql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
39
38
|
queryRes = await pgClient.query({
|
|
40
39
|
text: pgSql,
|
|
41
40
|
values: executeSqlArgs || [],
|
|
42
41
|
});
|
|
42
|
+
this.logger.debug('[CrudProExecuteSqlService] executeSqlCfgModel_postgres', pgSql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
43
43
|
}
|
|
44
44
|
else if (sqlCfgModel.sqlDbType === keys_1.SqlDbType.sqlserver) {
|
|
45
45
|
// SQLServer
|
|
46
46
|
const mssql = (0, convertMsSql_1.replaceQuestionMarksForMssql)(sqlCfgModel.executeSql);
|
|
47
|
-
this.logger.debug('[CrudProExecuteSqlService]executeSqlCfgModel_sqlserver', mssql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
48
47
|
queryRes = await connection.query(mssql, executeSqlArgs);
|
|
48
|
+
this.logger.debug('[CrudProExecuteSqlService] executeSqlCfgModel_sqlserver', mssql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
51
|
// MYSQL
|
|
52
|
-
this.logger.debug('[CrudProExecuteSqlService]executeSqlCfgModel_mysql', sqlCfgModel.executeSql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
53
52
|
queryRes = await connection.query(sqlCfgModel.executeSql, executeSqlArgs);
|
|
53
|
+
this.logger.debug('[CrudProExecuteSqlService] executeSqlCfgModel_mysql', sqlCfgModel.executeSql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
54
54
|
}
|
|
55
55
|
const sqlRes = (0, convertMix_1.pickAndConvertRowsByMix)(queryRes, sqlCfgModel.sqlDbType);
|
|
56
56
|
const resObject = this.toQueryResByResPicker(sqlRes, queryRes, sqlCfgModel);
|
|
@@ -110,30 +110,8 @@ export declare enum CacheLevelEnum {
|
|
|
110
110
|
REDIS = "REDIS",
|
|
111
111
|
DISK = "DISK"
|
|
112
112
|
}
|
|
113
|
-
export declare enum CacheNameEnum {
|
|
114
|
-
CurdMixByDict = "CurdMixByDict",
|
|
115
|
-
CurdMixByLinkToCustom = "CurdMixByLinkToCustom",
|
|
116
|
-
CurdMixBySysConfig = "CurdMixBySysConfig",
|
|
117
|
-
CurdMixByWorkbench = "CurdMixByWorkbench",
|
|
118
|
-
GetParsedCrudStdAppInfo = "GetParsedCrudStdAppInfo",
|
|
119
|
-
GetWorkbenchMenu = "GetWorkbenchMenu",
|
|
120
|
-
GetNavPageInfo = "GetNavPageInfo",
|
|
121
|
-
GetEnumInfoByCode = "GetEnumInfoByCode",
|
|
122
|
-
UserSessionBySessionId = "UserSessionBySessionId",
|
|
123
|
-
UserSessionByAsyncTaskId = "UserSessionByAsyncTaskId"
|
|
124
|
-
}
|
|
125
113
|
export interface IWorkbenchConfig {
|
|
126
114
|
nodeApiWhiteEnable?: boolean;
|
|
127
115
|
nodeApiWhiteList?: string[];
|
|
128
116
|
nodeApiWhitePrefix?: string[];
|
|
129
|
-
crudStdAppInfoCacheLevel?: CacheLevelEnum;
|
|
130
|
-
crudStdAppInfoCacheSecond?: number;
|
|
131
|
-
publicApiNavPageInfoCacheLevel?: CacheLevelEnum;
|
|
132
|
-
publicApiNavPageInfoCacheSecond?: number;
|
|
133
|
-
publicApiMenuCacheLevel?: CacheLevelEnum;
|
|
134
|
-
publicApiMenuCacheSecond?: number;
|
|
135
|
-
queryEnumInfoCacheLevel?: CacheLevelEnum;
|
|
136
|
-
queryEnumInfoCacheSecond?: number;
|
|
137
|
-
curdMixByCommonCacheLevel?: CacheLevelEnum;
|
|
138
|
-
curdMixByCommonCacheSecond?: number;
|
|
139
117
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CacheLevelEnum = exports.ProxyUserContextEnum = void 0;
|
|
4
4
|
var ProxyUserContextEnum;
|
|
5
5
|
(function (ProxyUserContextEnum) {
|
|
6
6
|
ProxyUserContextEnum[ProxyUserContextEnum["NO_PASS"] = 0] = "NO_PASS";
|
|
@@ -15,16 +15,3 @@ var CacheLevelEnum;
|
|
|
15
15
|
CacheLevelEnum["REDIS"] = "REDIS";
|
|
16
16
|
CacheLevelEnum["DISK"] = "DISK";
|
|
17
17
|
})(CacheLevelEnum = exports.CacheLevelEnum || (exports.CacheLevelEnum = {}));
|
|
18
|
-
var CacheNameEnum;
|
|
19
|
-
(function (CacheNameEnum) {
|
|
20
|
-
CacheNameEnum["CurdMixByDict"] = "CurdMixByDict";
|
|
21
|
-
CacheNameEnum["CurdMixByLinkToCustom"] = "CurdMixByLinkToCustom";
|
|
22
|
-
CacheNameEnum["CurdMixBySysConfig"] = "CurdMixBySysConfig";
|
|
23
|
-
CacheNameEnum["CurdMixByWorkbench"] = "CurdMixByWorkbench";
|
|
24
|
-
CacheNameEnum["GetParsedCrudStdAppInfo"] = "GetParsedCrudStdAppInfo";
|
|
25
|
-
CacheNameEnum["GetWorkbenchMenu"] = "GetWorkbenchMenu";
|
|
26
|
-
CacheNameEnum["GetNavPageInfo"] = "GetNavPageInfo";
|
|
27
|
-
CacheNameEnum["GetEnumInfoByCode"] = "GetEnumInfoByCode";
|
|
28
|
-
CacheNameEnum["UserSessionBySessionId"] = "UserSessionBySessionId";
|
|
29
|
-
CacheNameEnum["UserSessionByAsyncTaskId"] = "UserSessionByAsyncTaskId";
|
|
30
|
-
})(CacheNameEnum = exports.CacheNameEnum || (exports.CacheNameEnum = {}));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IRequestCfgModel, IVisitor } from '../libs/crud-pro/interfaces';
|
|
2
|
+
import { CacheLevelEnum } from "../models/SystemEntities";
|
|
2
3
|
/**
|
|
3
4
|
* 实体表公共字段
|
|
4
5
|
*/
|
|
@@ -107,7 +108,24 @@ export interface ICacheService {
|
|
|
107
108
|
setJsonObject(key: string, obj: any, cacheSecond?: number): Promise<any>;
|
|
108
109
|
removeItem(key: string): Promise<any>;
|
|
109
110
|
}
|
|
111
|
+
export declare enum CacheNameEnum {
|
|
112
|
+
CurdMixByAccount = "CurdMixByAccount",
|
|
113
|
+
CurdMixByDict = "CurdMixByDict",
|
|
114
|
+
CurdMixByLinkToCustom = "CurdMixByLinkToCustom",
|
|
115
|
+
CurdMixBySysConfig = "CurdMixBySysConfig",
|
|
116
|
+
CurdMixByWorkbench = "CurdMixByWorkbench",
|
|
117
|
+
GetParsedCrudStdAppInfo = "GetParsedCrudStdAppInfo",
|
|
118
|
+
GetWorkbenchMenu = "GetWorkbenchMenu",
|
|
119
|
+
GetNavPageInfo = "GetNavPageInfo",
|
|
120
|
+
GetEnumInfoByCode = "GetEnumInfoByCode",
|
|
121
|
+
UserSessionBySessionId = "UserSessionBySessionId",
|
|
122
|
+
UserSessionByAsyncTaskId = "UserSessionByAsyncTaskId"
|
|
123
|
+
}
|
|
124
|
+
export interface IWorkbenchConfigCacheLevel {
|
|
125
|
+
cacheLevel: CacheLevelEnum;
|
|
126
|
+
cacheSecond: number;
|
|
127
|
+
}
|
|
110
128
|
export interface IfatcmsCacheConfig {
|
|
111
129
|
diskCacheDir: string;
|
|
112
|
-
|
|
130
|
+
cacheConfig?: Record<CacheNameEnum, IWorkbenchConfigCacheLevel>;
|
|
113
131
|
}
|
package/dist/models/bizmodels.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StdCrudExportInputParamsAppType = exports.FILE_GET_TYPES = exports.CTX_WORKBENCH_CODE = exports.CTX_VISITOR_ACCOUNT_TYPE = exports.CTX_VISITOR_NICKNAME = exports.CTX_VISITOR_AVATAR = exports.CTX_VISITOR_ID = exports.PermRole = exports.PermFunc = exports.UploadCategoryType = exports.AccessType = void 0;
|
|
3
|
+
exports.CacheNameEnum = exports.StdCrudExportInputParamsAppType = exports.FILE_GET_TYPES = exports.CTX_WORKBENCH_CODE = exports.CTX_VISITOR_ACCOUNT_TYPE = exports.CTX_VISITOR_NICKNAME = exports.CTX_VISITOR_AVATAR = exports.CTX_VISITOR_ID = exports.PermRole = exports.PermFunc = exports.UploadCategoryType = exports.AccessType = void 0;
|
|
4
4
|
var AccessType;
|
|
5
5
|
(function (AccessType) {
|
|
6
6
|
AccessType["owner"] = "owner";
|
|
@@ -37,3 +37,17 @@ var StdCrudExportInputParamsAppType;
|
|
|
37
37
|
StdCrudExportInputParamsAppType["STD_CRUD"] = "STD_CRUD";
|
|
38
38
|
StdCrudExportInputParamsAppType["INNER_HTTP"] = "INNER_HTTP";
|
|
39
39
|
})(StdCrudExportInputParamsAppType = exports.StdCrudExportInputParamsAppType || (exports.StdCrudExportInputParamsAppType = {}));
|
|
40
|
+
var CacheNameEnum;
|
|
41
|
+
(function (CacheNameEnum) {
|
|
42
|
+
CacheNameEnum["CurdMixByAccount"] = "CurdMixByAccount";
|
|
43
|
+
CacheNameEnum["CurdMixByDict"] = "CurdMixByDict";
|
|
44
|
+
CacheNameEnum["CurdMixByLinkToCustom"] = "CurdMixByLinkToCustom";
|
|
45
|
+
CacheNameEnum["CurdMixBySysConfig"] = "CurdMixBySysConfig";
|
|
46
|
+
CacheNameEnum["CurdMixByWorkbench"] = "CurdMixByWorkbench";
|
|
47
|
+
CacheNameEnum["GetParsedCrudStdAppInfo"] = "GetParsedCrudStdAppInfo";
|
|
48
|
+
CacheNameEnum["GetWorkbenchMenu"] = "GetWorkbenchMenu";
|
|
49
|
+
CacheNameEnum["GetNavPageInfo"] = "GetNavPageInfo";
|
|
50
|
+
CacheNameEnum["GetEnumInfoByCode"] = "GetEnumInfoByCode";
|
|
51
|
+
CacheNameEnum["UserSessionBySessionId"] = "UserSessionBySessionId";
|
|
52
|
+
CacheNameEnum["UserSessionByAsyncTaskId"] = "UserSessionByAsyncTaskId";
|
|
53
|
+
})(CacheNameEnum = exports.CacheNameEnum || (exports.CacheNameEnum = {}));
|
|
@@ -19,26 +19,21 @@ const parseConfig_1 = require("../libs/utils/parseConfig");
|
|
|
19
19
|
const CurdMixByLinkToCustomService_1 = require("./curd/CurdMixByLinkToCustomService");
|
|
20
20
|
const global_config_1 = require("../libs/global-config/global-config");
|
|
21
21
|
const CacheServiceFactory_1 = require("./base/cache/CacheServiceFactory");
|
|
22
|
-
const
|
|
22
|
+
const bizmodels_1 = require("../models/bizmodels");
|
|
23
23
|
function filterEmpty(e) {
|
|
24
24
|
return e.label && typeof e.value !== 'undefined';
|
|
25
25
|
}
|
|
26
|
-
const DEFAULT_CACHE_LEVEL = SystemEntities_1.CacheLevelEnum.MEMORY;
|
|
27
|
-
const DEFAULT_CACHE_SECOND = 60 * 5;
|
|
28
26
|
let EnumInfoService = class EnumInfoService {
|
|
29
27
|
async queryEnumInfo(codeList, refreshCache) {
|
|
30
|
-
const { queryEnumInfoCacheLevel, queryEnumInfoCacheSecond } = this.ctx.workbenchInfoTools.getWorkbenchConfig() || {};
|
|
31
28
|
const getEnumInfoByCode = async (type, code) => {
|
|
32
29
|
if (type === CurdMixUtils_1.RelatedType.linkToCustom) {
|
|
33
30
|
return await this.queryEnumInfoByLinkToCustom(code);
|
|
34
31
|
}
|
|
35
32
|
const cacheKey = `${type}@@${code}`;
|
|
36
|
-
|
|
37
|
-
cacheLevel: queryEnumInfoCacheLevel || DEFAULT_CACHE_LEVEL,
|
|
38
|
-
cacheSecond: queryEnumInfoCacheSecond || DEFAULT_CACHE_SECOND,
|
|
33
|
+
return await this.cacheServiceFactory.getJsonObjectCache({
|
|
39
34
|
cacheKey,
|
|
40
35
|
refreshCache,
|
|
41
|
-
cacheName:
|
|
36
|
+
cacheName: bizmodels_1.CacheNameEnum.GetEnumInfoByCode,
|
|
42
37
|
getter: async () => {
|
|
43
38
|
if (type === CurdMixUtils_1.RelatedType.sysCfgEnum) {
|
|
44
39
|
return await this.queryEnumInfoBySysCfgEnum(code);
|
|
@@ -49,7 +44,6 @@ let EnumInfoService = class EnumInfoService {
|
|
|
49
44
|
return [];
|
|
50
45
|
},
|
|
51
46
|
});
|
|
52
|
-
return emums;
|
|
53
47
|
};
|
|
54
48
|
const result = [];
|
|
55
49
|
for (let i = 0; i < codeList.length; i++) {
|
|
@@ -19,7 +19,7 @@ const keys_1 = require("../libs/crud-pro/models/keys");
|
|
|
19
19
|
const SystemTables_1 = require("../models/SystemTables");
|
|
20
20
|
const global_config_1 = require("../libs/global-config/global-config");
|
|
21
21
|
const CacheServiceFactory_1 = require("./base/cache/CacheServiceFactory");
|
|
22
|
-
const
|
|
22
|
+
const bizmodels_1 = require("../models/bizmodels");
|
|
23
23
|
function pickUserAvatar(avatar) {
|
|
24
24
|
if (!avatar) {
|
|
25
25
|
return null;
|
|
@@ -62,7 +62,7 @@ let UserSessionService = class UserSessionService {
|
|
|
62
62
|
* @returns
|
|
63
63
|
*/
|
|
64
64
|
getUserSessionCacheService() {
|
|
65
|
-
return this.cacheServiceFactory.
|
|
65
|
+
return this.cacheServiceFactory.getCacheServiceByName(bizmodels_1.CacheNameEnum.UserSessionBySessionId);
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* 保存用户会话信息。
|
|
@@ -121,14 +121,11 @@ let UserSessionService = class UserSessionService {
|
|
|
121
121
|
}
|
|
122
122
|
return (0, functions_1.parseJsonObject)(asyncTaskObj.created_user_session);
|
|
123
123
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
cacheName: SystemEntities_1.CacheNameEnum.UserSessionByAsyncTaskId,
|
|
124
|
+
return await this.cacheServiceFactory.getJsonObjectCache({
|
|
125
|
+
cacheName: bizmodels_1.CacheNameEnum.UserSessionByAsyncTaskId,
|
|
127
126
|
cacheKey: taskSessionCacheKey,
|
|
128
|
-
cacheSecond: 3600,
|
|
129
127
|
getter: loadSessionInfo,
|
|
130
128
|
});
|
|
131
|
-
return sessionInfo1;
|
|
132
129
|
}
|
|
133
130
|
/**
|
|
134
131
|
* 专门给中间件点调用的
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { Context } from '@midwayjs/koa';
|
|
2
|
-
import { ICacheService } from '../../../models/bizmodels';
|
|
3
|
-
import { CacheLevelEnum, CacheNameEnum } from '../../../models/SystemEntities';
|
|
2
|
+
import { CacheNameEnum, ICacheService } from '../../../models/bizmodels';
|
|
4
3
|
import { RedisService } from '@midwayjs/redis';
|
|
5
4
|
interface IGetJsonObjectCacheParam {
|
|
6
|
-
cacheLevel: CacheLevelEnum;
|
|
7
5
|
cacheName: CacheNameEnum;
|
|
8
6
|
cacheKey: string;
|
|
9
|
-
cacheSecond: number;
|
|
10
7
|
refreshCache?: boolean;
|
|
11
8
|
getter: () => Promise<any>;
|
|
12
9
|
}
|
|
@@ -14,7 +11,8 @@ export declare class CacheServiceFactory {
|
|
|
14
11
|
protected ctx: Context;
|
|
15
12
|
private fatcmsCache;
|
|
16
13
|
protected redisService: RedisService;
|
|
17
|
-
getCacheService
|
|
14
|
+
private getCacheService;
|
|
15
|
+
getCacheServiceByName(cacheName: CacheNameEnum): ICacheService;
|
|
18
16
|
getJsonObjectCache(param: IGetJsonObjectCacheParam): Promise<any>;
|
|
19
17
|
}
|
|
20
18
|
export {};
|
|
@@ -18,33 +18,44 @@ const RedisCache_1 = require("./RedisCache");
|
|
|
18
18
|
const DiskCache_1 = require("./DiskCache");
|
|
19
19
|
const MemoryCache_1 = require("./MemoryCache");
|
|
20
20
|
const NoneCache_1 = require("./NoneCache");
|
|
21
|
+
const defaultCacheConfig = {
|
|
22
|
+
cacheLevel: SystemEntities_1.CacheLevelEnum.MEMORY,
|
|
23
|
+
cacheSecond: 60 * 5
|
|
24
|
+
};
|
|
21
25
|
let CacheServiceFactory = class CacheServiceFactory {
|
|
22
|
-
getCacheService(cacheLevelEnum, cacheName) {
|
|
26
|
+
getCacheService(cacheLevelEnum, cacheName, cacheSecond) {
|
|
23
27
|
switch (cacheLevelEnum) {
|
|
24
28
|
case SystemEntities_1.CacheLevelEnum.CONTEXT:
|
|
25
29
|
return new CtxCache_1.CtxCache(this.ctx, cacheName);
|
|
26
30
|
case SystemEntities_1.CacheLevelEnum.REDIS:
|
|
27
|
-
return new RedisCache_1.RedisCache(this.ctx, cacheName, this.redisService);
|
|
31
|
+
return new RedisCache_1.RedisCache(this.ctx, cacheName, this.redisService, cacheSecond);
|
|
28
32
|
case SystemEntities_1.CacheLevelEnum.DISK:
|
|
29
|
-
return new DiskCache_1.
|
|
33
|
+
return new DiskCache_1.DiskCache(this.ctx, cacheName, this.fatcmsCache, cacheSecond);
|
|
30
34
|
case SystemEntities_1.CacheLevelEnum.MEMORY:
|
|
31
|
-
return new MemoryCache_1.MemoryCache(this.ctx, cacheName);
|
|
35
|
+
return new MemoryCache_1.MemoryCache(this.ctx, cacheName, cacheSecond);
|
|
36
|
+
case SystemEntities_1.CacheLevelEnum.NONE:
|
|
37
|
+
return new NoneCache_1.NoneCache(this.ctx, cacheName);
|
|
32
38
|
default:
|
|
33
39
|
return new NoneCache_1.NoneCache(this.ctx, cacheName);
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
cacheSecond =
|
|
42
|
+
getCacheServiceByName(cacheName) {
|
|
43
|
+
var _a;
|
|
44
|
+
const cacheConfig = (((_a = this.fatcmsCache) === null || _a === void 0 ? void 0 : _a.cacheConfig) || {});
|
|
45
|
+
if (cacheConfig[cacheName]) {
|
|
46
|
+
const { cacheLevel, cacheSecond } = Object.assign({}, defaultCacheConfig, cacheConfig[cacheName]);
|
|
47
|
+
return this.getCacheService(cacheLevel, cacheName, cacheSecond);
|
|
41
48
|
}
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
const { cacheLevel, cacheSecond } = defaultCacheConfig;
|
|
50
|
+
return this.getCacheService(cacheLevel, cacheName, cacheSecond);
|
|
51
|
+
}
|
|
52
|
+
async getJsonObjectCache(param) {
|
|
53
|
+
const { cacheName, cacheKey, refreshCache, getter } = param;
|
|
54
|
+
const cacheService = this.getCacheServiceByName(cacheName);
|
|
55
|
+
let obj = await cacheService.getJsonObject(cacheKey);
|
|
45
56
|
if (!obj || refreshCache === true) {
|
|
46
57
|
obj = await getter();
|
|
47
|
-
cacheService.setJsonObject(
|
|
58
|
+
await cacheService.setJsonObject(cacheKey, obj);
|
|
48
59
|
}
|
|
49
60
|
return obj;
|
|
50
61
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ICacheService } from '../../../models/bizmodels';
|
|
2
|
-
import { CacheNameEnum } from
|
|
2
|
+
import { CacheNameEnum } from "../../../models/bizmodels";
|
|
3
3
|
import { Context } from '@midwayjs/koa';
|
|
4
4
|
export declare class CtxCache implements ICacheService {
|
|
5
5
|
private ctx;
|
|
@@ -11,9 +11,8 @@ export declare class CtxCache implements ICacheService {
|
|
|
11
11
|
* 设置缓存对象
|
|
12
12
|
* @param key
|
|
13
13
|
* @param obj
|
|
14
|
-
* @param expireSecond 过期时间,单位秒
|
|
15
14
|
* @returns
|
|
16
15
|
*/
|
|
17
|
-
setJsonObject(key: string, obj: any
|
|
16
|
+
setJsonObject(key: string, obj: any): Promise<any>;
|
|
18
17
|
removeItem(key: string): Promise<any>;
|
|
19
18
|
}
|
|
@@ -23,10 +23,9 @@ class CtxCache {
|
|
|
23
23
|
* 设置缓存对象
|
|
24
24
|
* @param key
|
|
25
25
|
* @param obj
|
|
26
|
-
* @param expireSecond 过期时间,单位秒
|
|
27
26
|
* @returns
|
|
28
27
|
*/
|
|
29
|
-
async setJsonObject(key, obj
|
|
28
|
+
async setJsonObject(key, obj) {
|
|
30
29
|
const cacheMap = this.getCacheMap();
|
|
31
30
|
cacheMap.set(key, obj);
|
|
32
31
|
}
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import { Context } from '@midwayjs/koa';
|
|
2
2
|
import { ICacheService, IfatcmsCacheConfig } from '../../../models/bizmodels';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class DiskCache implements ICacheService {
|
|
4
4
|
protected ctx: Context;
|
|
5
5
|
protected cacheName: string;
|
|
6
6
|
private fatcmsCache;
|
|
7
|
-
|
|
7
|
+
private cacheSecond;
|
|
8
|
+
constructor(ctx: Context, cacheName: string, fatcmsCache: IfatcmsCacheConfig, cacheSecond: number);
|
|
8
9
|
/**
|
|
9
10
|
* 获取缓存文件路径
|
|
10
11
|
* @param key
|
|
11
|
-
* @
|
|
12
|
+
* @param checkDirExist
|
|
13
|
+
* @private
|
|
12
14
|
*/
|
|
13
15
|
private getCacheFilePath;
|
|
14
16
|
getJsonObject(key: string): Promise<any>;
|
|
15
|
-
|
|
16
|
-
* 设置缓存对象
|
|
17
|
-
* @param key
|
|
18
|
-
* @param obj
|
|
19
|
-
* @param expireSecond 过期时间,单位秒
|
|
20
|
-
* @returns
|
|
21
|
-
*/
|
|
22
|
-
setJsonObject(key: string, obj: any, expireSecond?: number): Promise<any>;
|
|
17
|
+
setJsonObject(key: string, obj: any, cacheSecond0?: number): Promise<any>;
|
|
23
18
|
removeItem(key: string): Promise<any>;
|
|
24
19
|
}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DiskCache = void 0;
|
|
4
4
|
const md5 = require("md5");
|
|
5
5
|
const fs = require("fs/promises");
|
|
6
6
|
const fs2 = require("fs");
|
|
7
7
|
const path = require("path");
|
|
8
8
|
const functions_1 = require("../../../libs/utils/functions");
|
|
9
|
-
class
|
|
10
|
-
constructor(ctx, cacheName, fatcmsCache) {
|
|
9
|
+
class DiskCache {
|
|
10
|
+
constructor(ctx, cacheName, fatcmsCache, cacheSecond) {
|
|
11
11
|
this.ctx = ctx;
|
|
12
12
|
this.cacheName = cacheName;
|
|
13
13
|
this.fatcmsCache = fatcmsCache;
|
|
14
|
+
this.cacheSecond = cacheSecond;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* 获取缓存文件路径
|
|
17
18
|
* @param key
|
|
18
|
-
* @
|
|
19
|
+
* @param checkDirExist
|
|
20
|
+
* @private
|
|
19
21
|
*/
|
|
20
22
|
async getCacheFilePath(key, checkDirExist = true) {
|
|
21
23
|
const cacheDir0 = this.fatcmsCache.diskCacheDir;
|
|
@@ -42,21 +44,12 @@ class FatcmsBaseDiskCache {
|
|
|
42
44
|
return null;
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* @param key
|
|
48
|
-
* @param obj
|
|
49
|
-
* @param expireSecond 过期时间,单位秒
|
|
50
|
-
* @returns
|
|
51
|
-
*/
|
|
52
|
-
async setJsonObject(key, obj, expireSecond) {
|
|
53
|
-
if (!expireSecond) {
|
|
54
|
-
expireSecond = 60;
|
|
55
|
-
}
|
|
47
|
+
async setJsonObject(key, obj, cacheSecond0) {
|
|
48
|
+
const cacheSecond = cacheSecond0 || this.cacheSecond || 60;
|
|
56
49
|
const str = JSON.stringify({
|
|
57
50
|
data: obj,
|
|
58
51
|
key,
|
|
59
|
-
expireAt: Date.now() +
|
|
52
|
+
expireAt: Date.now() + cacheSecond * 1000,
|
|
60
53
|
});
|
|
61
54
|
const cacheFilePath = await this.getCacheFilePath(key);
|
|
62
55
|
try {
|
|
@@ -78,4 +71,4 @@ class FatcmsBaseDiskCache {
|
|
|
78
71
|
}
|
|
79
72
|
}
|
|
80
73
|
}
|
|
81
|
-
exports.
|
|
74
|
+
exports.DiskCache = DiskCache;
|
|
@@ -3,16 +3,10 @@ import { ICacheService } from '../../../models/bizmodels';
|
|
|
3
3
|
export declare class MemoryCache implements ICacheService {
|
|
4
4
|
protected ctx: Context;
|
|
5
5
|
protected cacheName: string;
|
|
6
|
-
|
|
6
|
+
protected cacheSecond: number;
|
|
7
|
+
constructor(ctx: Context, cacheName: string, cacheSecond: number);
|
|
7
8
|
private getLruCache;
|
|
8
9
|
getJsonObject(key: string): Promise<any>;
|
|
9
|
-
|
|
10
|
-
* 设置缓存对象
|
|
11
|
-
* @param key
|
|
12
|
-
* @param obj
|
|
13
|
-
* @param expireSecond 过期时间,单位秒
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
setJsonObject(key: string, obj: any, expireSecond?: number): Promise<any>;
|
|
10
|
+
setJsonObject(key: string, obj: any, cacheSecond0: number): Promise<any>;
|
|
17
11
|
removeItem(key: string): Promise<any>;
|
|
18
12
|
}
|
|
@@ -4,14 +4,15 @@ exports.MemoryCache = void 0;
|
|
|
4
4
|
const lru_cache_1 = require("lru-cache");
|
|
5
5
|
const LRU_CACHE_MAP = new Map();
|
|
6
6
|
class MemoryCache {
|
|
7
|
-
constructor(ctx, cacheName) {
|
|
7
|
+
constructor(ctx, cacheName, cacheSecond) {
|
|
8
8
|
this.ctx = ctx;
|
|
9
9
|
this.cacheName = cacheName;
|
|
10
|
+
this.cacheSecond = cacheSecond;
|
|
10
11
|
}
|
|
11
12
|
getLruCache() {
|
|
12
13
|
if (!LRU_CACHE_MAP.has(this.cacheName)) {
|
|
13
14
|
const lruCache = new lru_cache_1.LRUCache({
|
|
14
|
-
max:
|
|
15
|
+
max: 2000,
|
|
15
16
|
ttl: 1000 * 60 * 60 * 24,
|
|
16
17
|
ttlAutopurge: true,
|
|
17
18
|
});
|
|
@@ -32,22 +33,13 @@ class MemoryCache {
|
|
|
32
33
|
return null;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* @param key
|
|
38
|
-
* @param obj
|
|
39
|
-
* @param expireSecond 过期时间,单位秒
|
|
40
|
-
* @returns
|
|
41
|
-
*/
|
|
42
|
-
async setJsonObject(key, obj, expireSecond) {
|
|
36
|
+
async setJsonObject(key, obj, cacheSecond0) {
|
|
37
|
+
const cacheSecond = cacheSecond0 || this.cacheSecond || 60;
|
|
43
38
|
const lruCache = this.getLruCache();
|
|
44
|
-
if (!expireSecond) {
|
|
45
|
-
expireSecond = 60;
|
|
46
|
-
}
|
|
47
39
|
const saveObj = {
|
|
48
40
|
data: obj,
|
|
49
41
|
key,
|
|
50
|
-
expireAt: Date.now() +
|
|
42
|
+
expireAt: Date.now() + cacheSecond * 1000,
|
|
51
43
|
};
|
|
52
44
|
lruCache.set(key, saveObj);
|
|
53
45
|
return true;
|
|
@@ -5,16 +5,10 @@ export declare class RedisCache implements ICacheService {
|
|
|
5
5
|
protected ctx: Context;
|
|
6
6
|
protected cacheName: string;
|
|
7
7
|
protected redisService: RedisService;
|
|
8
|
-
|
|
8
|
+
protected cacheSecond: number;
|
|
9
|
+
constructor(ctx: Context, cacheName: string, redisService: RedisService, cacheSecond: number);
|
|
9
10
|
private getCacheKey;
|
|
10
11
|
getJsonObject(key: string): Promise<any>;
|
|
11
|
-
|
|
12
|
-
* 设置缓存对象
|
|
13
|
-
* @param key
|
|
14
|
-
* @param obj
|
|
15
|
-
* @param expireSecond 过期时间,单位秒
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
setJsonObject(key: string, obj: any, expireSecond?: number): Promise<any>;
|
|
12
|
+
setJsonObject(key: string, obj: any, cacheSecond0?: number): Promise<any>;
|
|
19
13
|
removeItem(key: string): Promise<any>;
|
|
20
14
|
}
|
|
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RedisCache = void 0;
|
|
4
4
|
const functions_1 = require("../../../libs/utils/functions");
|
|
5
5
|
class RedisCache {
|
|
6
|
-
constructor(ctx, cacheName, redisService) {
|
|
6
|
+
constructor(ctx, cacheName, redisService, cacheSecond) {
|
|
7
7
|
this.ctx = ctx;
|
|
8
8
|
this.cacheName = cacheName;
|
|
9
9
|
this.redisService = redisService;
|
|
10
|
+
this.cacheSecond = cacheSecond;
|
|
10
11
|
}
|
|
11
12
|
getCacheKey(key) {
|
|
12
13
|
return `${this.cacheName}${key}`;
|
|
@@ -16,24 +17,15 @@ class RedisCache {
|
|
|
16
17
|
const str = await this.redisService.get(cacheKey);
|
|
17
18
|
return (0, functions_1.parseJsonObject)(str);
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* @param key
|
|
22
|
-
* @param obj
|
|
23
|
-
* @param expireSecond 过期时间,单位秒
|
|
24
|
-
* @returns
|
|
25
|
-
*/
|
|
26
|
-
async setJsonObject(key, obj, expireSecond) {
|
|
20
|
+
async setJsonObject(key, obj, cacheSecond0) {
|
|
21
|
+
const cacheSecond = cacheSecond0 || this.cacheSecond || 60;
|
|
27
22
|
const cacheKey = this.getCacheKey(key);
|
|
28
|
-
if (!expireSecond) {
|
|
29
|
-
expireSecond = 60;
|
|
30
|
-
}
|
|
31
23
|
const str = JSON.stringify(obj);
|
|
32
|
-
return this.redisService.set(cacheKey, str, 'EX',
|
|
24
|
+
return this.redisService.set(cacheKey, str, 'EX', cacheSecond);
|
|
33
25
|
}
|
|
34
26
|
async removeItem(key) {
|
|
35
27
|
const cacheKey = this.getCacheKey(key);
|
|
36
|
-
return
|
|
28
|
+
return this.redisService.del(cacheKey);
|
|
37
29
|
}
|
|
38
30
|
}
|
|
39
31
|
exports.RedisCache = RedisCache;
|