mirror of
https://github.com/PrivateCaptcha/PrivateCaptcha.git
synced 2026-02-12 00:39:29 -06:00
Cleanup user caches on logout
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user