affinity

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalManager = NewManager(45 * time.Minute)

Functions

func DeriveSessionKey

func DeriveSessionKey(r *http.Request, req *providers.ChatRequest) string

DeriveSessionKey generates a stable hash for a conversation turn

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(ttl time.Duration) *Manager

func (*Manager) EvictAffinity added in v0.4.0

func (m *Manager) EvictAffinity(sessionKey, providerID, accountID string) bool

EvictAffinity evicts a session pin ONLY when it points to accountID (or if accountID is empty). Matches OmniRoute parity (#6219: evictSessionAccountAffinityForConnection) so failovers do not remain pinned to an exhausted or rate-limited account.

func (*Manager) GetAffinity

func (m *Manager) GetAffinity(sessionKey, providerID string) string

GetAffinity returns pinned account ID if still valid

func (*Manager) InvalidateAffinity

func (m *Manager) InvalidateAffinity(sessionKey, providerID string)

InvalidateAffinity breaks affinity when account returns 429/401/403

func (*Manager) ListSessions

func (m *Manager) ListSessions() []SessionRecord

func (*Manager) SetAffinity

func (m *Manager) SetAffinity(sessionKey, providerID, accountID string)

SetAffinity pins a session to a specific account

type SessionAffinity

type SessionAffinity struct {
	AccountID string
	CreatedAt time.Time
	LastSeen  time.Time
}

type SessionRecord

type SessionRecord struct {
	Key       string    `json:"key"`
	AccountID string    `json:"account_id"`
	CreatedAt time.Time `json:"created_at"`
	LastSeen  time.Time `json:"last_seen"`
	AgeSec    int64     `json:"age_sec"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL