fix(apikey):修复apikey缓存导致模型不可用的问题
This commit is contained in:
1 parent
4f749930d6
commit
01459d29ce
3 files changed
+14
No files matched your search
@@ -1405,3 +1405,9 @@ func (p *DataProviderImpl) CheckApiKeyModelAccess(ctx context.Context, apiKeyID
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// InvalidateApiKeyModelCache 清除指定 API Key 的模型权限缓存
|
||||
func (p *DataProviderImpl) InvalidateApiKeyModelCache(ctx context.Context, apiKeyID int64) {
|
||||
cacheKey := strconv.FormatInt(apiKeyID, 10)
|
||||
apiKeyModelCache.Delete(ctx, cacheKey)
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/qianfree/team-api/internal/logic/billing"
|
||||
lcommon "github.com/qianfree/team-api/internal/logic/common"
|
||||
"github.com/qianfree/team-api/internal/logic/relay"
|
||||
lrelay "github.com/qianfree/team-api/internal/logic/relay"
|
||||
"github.com/qianfree/team-api/internal/middleware"
|
||||
do "github.com/qianfree/team-api/internal/model/do"
|
||||
|
||||
@@ -472,6 +473,8 @@ func (s *sTenant) ApiKeyUpdate(ctx context.Context, req *v1.TenantApiKeyUpdateRe
|
||||
|
||||
if hasUpdate || req.ModelNames != nil {
|
||||
relay.InvalidateApiKey(ctx, info.KeyPrefix)
|
||||
// 失效模型权限缓存(修复:更新模型范围后缓存未失效的问题)
|
||||
lrelay.NewDataProvider().InvalidateApiKeyModelCache(ctx, keyID)
|
||||
}
|
||||
|
||||
return &v1.TenantApiKeyUpdateRes{}, nil
|
||||
@@ -527,6 +530,8 @@ func (s *sTenant) ApiKeyUpdateScopes(ctx context.Context, req *v1.TenantApiKeyUp
|
||||
}
|
||||
|
||||
relay.InvalidateApiKey(ctx, info.KeyPrefix)
|
||||
// 失效模型权限缓存(修复:更新模型范围后缓存未失效的问题)
|
||||
lrelay.NewDataProvider().InvalidateApiKeyModelCache(ctx, keyID)
|
||||
|
||||
return &v1.TenantApiKeyUpdateScopesRes{}, nil
|
||||
}
|
||||
|
||||
@@ -87,6 +87,9 @@ type DataProvider interface {
|
||||
// InvalidateMemberModelCache 清除指定成员的模型范围缓存。
|
||||
InvalidateMemberModelCache(ctx context.Context, tenantID, userID int64)
|
||||
|
||||
// InvalidateApiKeyModelCache 清除指定 API Key 的模型权限缓存。
|
||||
InvalidateApiKeyModelCache(ctx context.Context, apiKeyID int64)
|
||||
|
||||
// MaterializeSelection 由新调度引擎的决策构造 ChannelSelection:
|
||||
// 从目录快照取转发元数据,按 keyID 解密渠道 Key(keyID=0 时取渠道首个 active Key)。
|
||||
MaterializeSelection(ctx context.Context, channelID, keyID int64, modelName string) (*ChannelSelection, error)
|
||||
|
||||
Reference in new issue
Block a user