Commit 7d58992a by 宋毅

tj

parent a42f6ffe
......@@ -20,7 +20,7 @@ class CacheBase {
async cache(inputkey, val, ex, ...items) {
const cachekey = this.prefix + inputkey;
var cacheValue = await this.redisClient.get(cachekey);
if (!cacheValue || cacheValue == "undefined" || cacheValue == "null" || this.isdebug) {
if (!cacheValue || cacheValue == "undefined" || cacheValue == "null" || this.isdebug) {
var objvalstr = await this.buildCacheVal(cachekey, inputkey, val, ex, ...items);
if (!objvalstr) {
return null;
......@@ -34,11 +34,12 @@ class CacheBase {
this.redisClient.sadd(this.cacheCacheKeyPrefix, [cachekey + "|" + this.desc]);
return JSON.parse(objvalstr);
} else {
this.redisClient.setWithEx(cachekey, cacheValue, ex);
return JSON.parse(cacheValue);
}
}
async invalidate(inputkey){
const cachekey=this.prefix+inputkey;
async invalidate(inputkey) {
const cachekey = this.prefix + inputkey;
this.redisClient.delete(cachekey);
return 0;
}
......
......@@ -3,6 +3,7 @@ const uuidv4 = require('uuid/v4');
class AuthUtils {
constructor() {
this.cacheManager = system.getObject("db.common.cacheManager");
this.exTime = 5 * 3600;//缓存过期时间,5小时
}
getUUID() {
var uuid = uuidv4();
......@@ -16,11 +17,11 @@ class AuthUtils {
*/
async getTokenInfo(appkey, secret) {
var rtnKey = this.getUUID();
var cacheAccessKey = await this.cacheManager["ApiAccessKeyClientCache"].cache(appkey, rtnKey, 3600);
var cacheAccessKey = await this.cacheManager["ApiAccessKeyClientCache"].cache(appkey, rtnKey, this.exTime);
if (cacheAccessKey) {
rtnKey = cacheAccessKey.accessKey;
}//获取之前的token值
var appData = await this.cacheManager["ApiAccessKeyCache"].cache(rtnKey, secret, 3600, appkey);
var appData = await this.cacheManager["ApiAccessKeyCache"].cache(rtnKey, secret, this.exTime, appkey);
if (!appData) {
return system.getResultFail(system.getAppInfoFail, "key或secret错误.");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment