daf10907e4
新增 token 缓存失效接口并在刷新后清理 401 限流支持自定义规则与可配置冷却时间 补齐缓存失效与 401 处理测试 测试: make test
18 lines
663 B
Go
18 lines
663 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// GeminiTokenCache stores short-lived access tokens and coordinates refresh to avoid stampedes.
|
|
type GeminiTokenCache interface {
|
|
// cacheKey should be stable for the token scope; for GeminiCli OAuth we primarily use project_id.
|
|
GetAccessToken(ctx context.Context, cacheKey string) (string, error)
|
|
SetAccessToken(ctx context.Context, cacheKey string, token string, ttl time.Duration) error
|
|
DeleteAccessToken(ctx context.Context, cacheKey string) error
|
|
|
|
AcquireRefreshLock(ctx context.Context, cacheKey string, ttl time.Duration) (bool, error)
|
|
ReleaseRefreshLock(ctx context.Context, cacheKey string) error
|
|
}
|