0

What's a good way to expire all sessions for a particular user? I thought of maintaining of separate map of user->session, but I'm not sure how to update the map when the session cookies expire.

yayitswei
  • 4,587
  • 5
  • 27
  • 34

1 Answers1

1

Assuming you have all sessions in memory using an atom or something similar (which I don't think to be something production-wise) you can do this:

Store sessions in a map with own properties:

sessions = {
  s1 -> {...}
  s2 -> {...}
  s3 -> {...}
  ...
}

Store user sessions in a separate map of sets:

user-sessions = {
 user1 -> #{s1 s2 s3}
 user2 -> #{s4 s5 s6}
}

You'll need to solve the following operations which need to update the set:

  • Add new session :s to :user

    (assoc user-sessions :user (conj (:user user-sessions) :s))

  • Remove session :s from :user

    (assoc user-sessions :user (disj (:user user-sessions) :s))

guilespi
  • 4,672
  • 1
  • 15
  • 24