gemini_token_cache.go 663 B

1234567891011121314151617
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. )
  6. // GeminiTokenCache stores short-lived access tokens and coordinates refresh to avoid stampedes.
  7. type GeminiTokenCache interface {
  8. // cacheKey should be stable for the token scope; for GeminiCli OAuth we primarily use project_id.
  9. GetAccessToken(ctx context.Context, cacheKey string) (string, error)
  10. SetAccessToken(ctx context.Context, cacheKey string, token string, ttl time.Duration) error
  11. DeleteAccessToken(ctx context.Context, cacheKey string) error
  12. AcquireRefreshLock(ctx context.Context, cacheKey string, ttl time.Duration) (bool, error)
  13. ReleaseRefreshLock(ctx context.Context, cacheKey string) error
  14. }