|
@@ -186,12 +186,15 @@ func GetAuthTokenWithOptions(host string) (_err error, token *authToken) {
|
|
|
log.Println("未匹配到host:", host)
|
|
|
return errors.New("host未匹配到"), token
|
|
|
}
|
|
|
- redisKey := fmt.Sprintf("oneclick_token_%s", host)
|
|
|
- // 查缓存
|
|
|
- if reidsCatche, redisErr := redis.GetBytes("other", redisKey); redisErr == nil && reidsCatche != nil {
|
|
|
- errs := json.Unmarshal(*reidsCatche, &token)
|
|
|
- if errs == nil && token != nil {
|
|
|
- return nil, token
|
|
|
+ // 是否走缓存
|
|
|
+ redisKey := fmt.Sprintf(initjson.OneClick.TokenCache.Key, host)
|
|
|
+ if initjson.OneClick.TokenCache.Open {
|
|
|
+ // 查缓存
|
|
|
+ if reidsCatche, redisErr := redis.GetBytes("other", redisKey); redisErr == nil && reidsCatche != nil {
|
|
|
+ errs := json.Unmarshal(*reidsCatche, &token)
|
|
|
+ if errs == nil && token != nil {
|
|
|
+ return nil, token
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
var (
|
|
@@ -236,9 +239,11 @@ func GetAuthTokenWithOptions(host string) (_err error, token *authToken) {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
- // 存缓存
|
|
|
- if bytes, err := json.Marshal(token); err == nil && bytes != nil {
|
|
|
- _ = redis.PutBytes("other", redisKey, &bytes, 60*9)
|
|
|
+ if initjson.OneClick.TokenCache.Open {
|
|
|
+ // 存缓存
|
|
|
+ if bytes, err := json.Marshal(token); err == nil && bytes != nil {
|
|
|
+ _ = redis.PutBytes("other", redisKey, &bytes, initjson.OneClick.TokenCache.Timeout)
|
|
|
+ }
|
|
|
}
|
|
|
return
|
|
|
}
|