daf10907e4
新增 token 缓存失效接口并在刷新后清理 401 限流支持自定义规则与可配置冷却时间 补齐缓存失效与 401 处理测试 测试: make test
36 lines
889 B
Go
36 lines
889 B
Go
package service
|
|
|
|
import "context"
|
|
|
|
type TokenCacheInvalidator interface {
|
|
InvalidateToken(ctx context.Context, account *Account) error
|
|
}
|
|
|
|
type CompositeTokenCacheInvalidator struct {
|
|
geminiCache GeminiTokenCache
|
|
}
|
|
|
|
func NewCompositeTokenCacheInvalidator(geminiCache GeminiTokenCache) *CompositeTokenCacheInvalidator {
|
|
return &CompositeTokenCacheInvalidator{
|
|
geminiCache: geminiCache,
|
|
}
|
|
}
|
|
|
|
func (c *CompositeTokenCacheInvalidator) InvalidateToken(ctx context.Context, account *Account) error {
|
|
if c == nil || c.geminiCache == nil || account == nil {
|
|
return nil
|
|
}
|
|
if account.Type != AccountTypeOAuth {
|
|
return nil
|
|
}
|
|
|
|
switch account.Platform {
|
|
case PlatformGemini:
|
|
return c.geminiCache.DeleteAccessToken(ctx, GeminiTokenCacheKey(account))
|
|
case PlatformAntigravity:
|
|
return c.geminiCache.DeleteAccessToken(ctx, AntigravityTokenCacheKey(account))
|
|
default:
|
|
return nil
|
|
}
|
|
}
|