Commit 7d58992a by 宋毅

tj

parent a42f6ffe
...@@ -34,11 +34,12 @@ class CacheBase { ...@@ -34,11 +34,12 @@ class CacheBase {
this.redisClient.sadd(this.cacheCacheKeyPrefix, [cachekey + "|" + this.desc]); this.redisClient.sadd(this.cacheCacheKeyPrefix, [cachekey + "|" + this.desc]);
return JSON.parse(objvalstr); return JSON.parse(objvalstr);
} else { } else {
this.redisClient.setWithEx(cachekey, cacheValue, ex);
return JSON.parse(cacheValue); return JSON.parse(cacheValue);
} }
} }
async invalidate(inputkey){ async invalidate(inputkey) {
const cachekey=this.prefix+inputkey; const cachekey = this.prefix + inputkey;
this.redisClient.delete(cachekey); this.redisClient.delete(cachekey);
return 0; return 0;
} }
......
...@@ -3,6 +3,7 @@ const uuidv4 = require('uuid/v4'); ...@@ -3,6 +3,7 @@ const uuidv4 = require('uuid/v4');
class AuthUtils { class AuthUtils {
constructor() { constructor() {
this.cacheManager = system.getObject("db.common.cacheManager"); this.cacheManager = system.getObject("db.common.cacheManager");
this.exTime = 5 * 3600;//缓存过期时间,5小时
} }
getUUID() { getUUID() {
var uuid = uuidv4(); var uuid = uuidv4();
...@@ -16,11 +17,11 @@ class AuthUtils { ...@@ -16,11 +17,11 @@ class AuthUtils {
*/ */
async getTokenInfo(appkey, secret) { async getTokenInfo(appkey, secret) {
var rtnKey = this.getUUID(); 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) { if (cacheAccessKey) {
rtnKey = cacheAccessKey.accessKey; rtnKey = cacheAccessKey.accessKey;
}//获取之前的token值 }//获取之前的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) { if (!appData) {
return system.getResultFail(system.getAppInfoFail, "key或secret错误."); 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