Cleanup user caches on logout

This commit is contained in:
Taras Kushnir
2025-12-19 10:09:31 +01:00
parent c6ddaf7a23
commit 77cb6e987d
2 changed files with 14 additions and 0 deletions

View File

@@ -2796,3 +2796,16 @@ func (impl *BusinessStoreImpl) RetrieveOrgPropertiesCount(ctx context.Context, o
return count, nil
}
func (impl *BusinessStoreImpl) CleanupUserCache(ctx context.Context, userID int32) {
_ = impl.cache.Delete(ctx, userOrgsCacheKey(userID))
_ = impl.cache.Delete(ctx, UserAPIKeysCacheKey(userID))
_ = impl.cache.Delete(ctx, userPropertiesCountCacheKey(userID))
tnow := time.Now().UTC().Truncate(24 * time.Hour)
for _, cacheDays := range []int{ /*14,*/ 30, 90, 180, 365} {
cachedAfter := tnow.AddDate(0 /*years*/, 0 /*months*/, -cacheDays)
key := cachedAfter.Format(time.DateOnly)
_ = impl.cache.Delete(ctx, userAuditLogsCacheKey(userID, key))
}
}

View File

@@ -119,6 +119,7 @@ func (s *Server) logout(w http.ResponseWriter, r *http.Request) {
sess := s.Session(w, r)
if userID, ok := sess.Get(ctx, session.KeyUserID).(int32); ok {
s.Store.AuditLog().RecordEvent(ctx, newUserAuthAuditLogEvent(userID, common.AuditLogActionLogout), common.AuditLogSourcePortal)
s.Store.Impl().CleanupUserCache(ctx, userID)
}
s.Sessions.SessionDestroy(w, r)