Reputation: 4687
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.
Upvotes: 0
Views: 63
Reputation: 4702
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))
Upvotes: 1