In memory session storage

Hello All,

I am using this https://docs.openvidu.io/en/2.15.0/tutorials/openvidu-js-java/ as a reference while developing my Java based application.

I can see that we are using HashMap to store sessions and tokens.

I am talking about this piece of code.

// Collection to pair session names and OpenVidu Session objects
private Map<String, Session> mapSessions = new ConcurrentHashMap<>();
// Collection to pair session names and tokens (the inner Map pairs tokens and role associated)
private Map<String, Map<String, OpenViduRole>> mapSessionNamesTokens = new ConcurrentHashMap<>();

As the number of users grows, the size of this collection will grow. I know the details will be removed once the user ends the session but can we really depend on this? What if the user didn’t click on the end call button (to remove from collection) in my case?

Is there any efficient way to handle this? I was thinking to store in the database.

What if the user didn’t click on the end call button (to remove from collection) in my case?

If you don’t want some user being able to remain connected to a session after some condition, you should control that condition and evict the participant from you application’s server side.

I was thinking to store in the database.

It really doesn’t matter where you store the data. The tutorials do it in memory collections for the shake of simplicity, but you can store it wherever you want.

Thanks @pabloFuente.