Explorar el Código

pc 端登录新增缓存func

evan.hong hace 4 años
padre
commit
9d90cce6e4
Se han modificado 2 ficheros con 14 adiciones y 1 borrados
  1. 2 1
      utils/auth/auth.go
  2. 12 0
      utils/token_store.go

+ 2 - 1
utils/auth/auth.go

@@ -73,7 +73,8 @@ func AddToGlobalTokenStore(c *entitys.CtrlContext, userInfo *sysmodel.SysUser) (
 		token.Result = 200
 		token.ServerIp = ""
 		token.Domain = userInfo.Domain
-		sysutils.GetGlobalTokenStore().Set(sec_tooken, token)
+		//sysutils.GetGlobalTokenStore().Set(sec_tooken, token)
+		sysutils.GetGlobalTokenStore().SetPc(sec_tooken, token)
 	} else {
 		token = v
 	}

+ 12 - 0
utils/token_store.go

@@ -2,6 +2,7 @@ package utils
 
 import (
 	"errors"
+	"fmt"
 	"strings"
 	"sync"
 	"time"
@@ -14,6 +15,7 @@ import (
 type TokenStore interface {
 	Get(string) *entitys.Token
 	Set(string, *entitys.Token)
+	SetPc(string, *entitys.Token)
 	Remove(key string)
 	Refresh(key string) *entitys.Token
 }
@@ -59,6 +61,16 @@ func (t *MemoryStore) Set(key string, v *entitys.Token) {
 	}
 }
 
+func (t *MemoryStore) SetPc(key string, v *entitys.Token) {
+	t.lock.Lock()
+	defer t.lock.Unlock()
+	if val, ok := t.tokens[key]; !ok {
+		t.tokens[key] = v
+	} else if val != v {
+		t.tokens[key] = v
+	}
+}
+
 func (t *MemoryStore) Remove(key string) {
 	t.lock.Lock()
 	defer t.lock.Unlock()