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

Function updateUserCacheField

model/user_cache.go:271–283  ·  view source on GitHub ↗

updateUserCacheField prevents individual cache refreshes from bypassing the auth-version fence. It intentionally does nothing when the complete hash is absent; the next GetUserCache call will repopulate it from the database.

(userId int, field string, value interface{})

Source from the content-addressed store, hash-verified

269// auth-version fence. It intentionally does nothing when the complete hash is
270// absent; the next GetUserCache call will repopulate it from the database.
271func updateUserCacheField(userId int, field string, value interface{}) error {
272 if !common.RedisEnabled {
273 return nil
274 }
275 var user User
276 if err := DB.Select("id", "auth_version").Where("id = ?", userId).First(&user).Error; err != nil {
277 return err
278 }
279 if user.AuthVersion <= 0 {
280 return fmt.Errorf("invalid user auth version")
281 }
282 return updateUserCacheFieldAtVersion(userId, field, value, user.AuthVersion)
283}
284
285// GetUserLanguage returns the user's language preference from cache
286// Uses the existing GetUserCache mechanism for efficiency

Callers 4

updateUserStatusCacheFunction · 0.85
updateUserEmailCacheFunction · 0.85
updateUserNameCacheFunction · 0.85
updateUserSettingCacheFunction · 0.85

Calls 1

Tested by

no test coverage detected