MCPcopy Create free account
hub / github.com/QuantumNous/new-api / GetUserCache

Function GetUserCache

model/user_cache.go:94–121  ·  view source on GitHub ↗

GetUserCache gets complete user cache from hash

(userId int)

Source from the content-addressed store, hash-verified

92
93// GetUserCache gets complete user cache from hash
94func GetUserCache(userId int) (*UserBase, error) {
95 // Try getting from Redis first
96 userCache, err := cacheGetUserBase(userId)
97 if err == nil {
98 return userCache, nil
99 }
100
101 // Redis misses and read failures both fall back to the shared database. A
102 // version fence newer than the database is the one exception: allowing that
103 // snapshot would re-authorize a user while a restrictive update is pending.
104 user, err := GetUserById(userId, false)
105 if err != nil {
106 return nil, err
107 }
108 if common.RedisEnabled {
109 floor, floorErr := getUserAuthVersionFloor(userId)
110 if floorErr == nil && floor > user.AuthVersion {
111 return nil, ErrUserAuthCachePending
112 }
113 if err := populateUserCache(*user); err != nil {
114 if errors.Is(err, ErrUserAuthCachePending) {
115 return nil, err
116 }
117 common.SysLog("failed to synchronously populate user cache: " + err.Error())
118 }
119 }
120 return user.ToBaseUser(), nil
121}
122
123func cacheGetUserBase(userId int) (*UserBase, error) {
124 if !common.RedisEnabled {

Callers 15

TokenAuthReadOnlyFunction · 0.92
TokenAuthFunction · 0.92
testChannelFunction · 0.92
PlaygroundFunction · 0.92
GetPricingFunction · 0.92
tasksToDtoFunction · 0.92
GetUserModelsFunction · 0.92
createLoginSessionFunction · 0.92
ValidateLoginSessionFunction · 0.92
RefreshLoginSessionFunction · 0.92

Calls 7

SysLogFunction · 0.92
cacheGetUserBaseFunction · 0.85
GetUserByIdFunction · 0.85
getUserAuthVersionFloorFunction · 0.85
populateUserCacheFunction · 0.85
ToBaseUserMethod · 0.80
ErrorMethod · 0.45