fix: update getToken function to include channelId in cache key

This commit is contained in:
liu.vaayne 2024-07-12 13:34:56 +08:00 committed by Vaayne
parent 688a7fc670
commit e52fde1895
2 changed files with 3 additions and 3 deletions

View File

@ -81,7 +81,7 @@ func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error) {
func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *meta.Meta) error { func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *meta.Meta) error {
adaptor.SetupCommonRequestHeader(c, req, meta) adaptor.SetupCommonRequestHeader(c, req, meta)
token, err := getToken(c, meta.Config.VertexAIADC) token, err := getToken(c, meta.ChannelId, meta.Config.VertexAIADC)
if err != nil { if err != nil {
return err return err
} }

View File

@ -31,8 +31,8 @@ var Cache = cache.New(50*time.Minute, 55*time.Minute)
const defaultScope = "https://www.googleapis.com/auth/cloud-platform" const defaultScope = "https://www.googleapis.com/auth/cloud-platform"
func getToken(ctx context.Context, adcJson string) (string, error) { func getToken(ctx context.Context, channelId int, adcJson string) (string, error) {
cacheKey := "vertexai-token" cacheKey := fmt.Sprintf("vertexai-token-%d", channelId)
if token, found := Cache.Get(cacheKey); found { if token, found := Cache.Get(cacheKey); found {
return token.(string), nil return token.(string), nil
} }