Files
backend/internal/pkg/auth/cache.go

23 lines
687 B
Go
Raw Normal View History

package auth
import "with_you/internal/cache"
// InvalidatePrincipalCache 失效用户的 Principal 缓存。
//
// 供角色变更、账户状态变更、登出等场景调用:让 RequireAuth 在下一次请求
// 重新从 IDP 加载用户与角色。键定义在本包以避免 service → middleware 的包循环。
func InvalidatePrincipalCache(cch cache.Cache, userID string) {
if cch == nil || userID == "" {
return
}
cch.Delete(PrincipalCacheKey(userID))
}
// InvalidateSessionCache 失效会话有效性缓存。
func InvalidateSessionCache(cch cache.Cache, sessionID string) {
if cch == nil || sessionID == "" {
return
}
cch.Delete(SessionCacheKey(sessionID))
}