feat: use cache to avoid database access (#158)

This commit is contained in:
JustSong
2023-06-20 19:09:49 +08:00
parent 4250064296
commit 3d76a974d1
5 changed files with 123 additions and 4 deletions

View File

@@ -36,8 +36,7 @@ func ValidateUserToken(key string) (token *Token, err error) {
if key == "" {
return nil, errors.New("未提供 token")
}
token = &Token{}
err = DB.Where("`key` = ?", key).First(token).Error
token, err = CacheGetTokenByKey(key)
if err == nil {
if token.Status != common.TokenStatusEnabled {
return nil, errors.New("该 token 状态不可用")