I am implementing a session structure.
I have a server side ConcurrentDictionary holding all the <SessionId, UserSession> .
When a new connection is established, the cookie is assigned to the client browser, perm or temp, depending on the RememberMe option.
When clients call the LogOut function, it removes the session from the dictionary.
However, when the client browser is simply closed or broken, and the cookie has been lost or expired or deleted, the server-side session object in memory remains in the dictionary and becomes a ghost. Over time, these ghosts will add up.
My question is how to improve the design so that dead sessions can be cleaned after they have expired?
I was thinking of making a timer service that runs a cleaning schedule, but it's not too elegant. Is there an easier way to do this without depending on the external service?
source share