Best way to save state with Tomcat / Scala?

What's the best way to preserve user state using Tomcat / Scala? My first thought is to persistently save session information in the session and redirect the user to the login page if there is no session information for the account. Is this a viable model or is there a smarter way to store user information? I am trying to replicate the main shopping cart site and I am just looking at the problem right now.

+2


source to share


1 answer


There are many ways to trick this cat. You can store your information in a session, provided your objects are light enough (and your traffic volumes are low enough). This is probably the simplest solution, but you may run into difficulties when you need to scale or group.

From Tomcat experience scaling, clustering, db session storage, etc. not very good for me.

Another way would be to manage your token with a cookie. You then store the actual information for a given user token on the server. The most naive implementation would just have a memory card, but that would have the drawback of losing all data when the application restarts.



You can store the information in a database and search with a user token on every request (perhaps with some caching strategy). It also allows you to scale to multiple application servers without much worrying about clustering β€” each instance simply looks for a user token and performs a lookup query on the shared database.

If you end up with an actual implementation behind a good interface, you can start with a simple / cheap session solution and gradually move on to a more complex implementation if you need to later. One caveat is that you have to be extra careful not to leak information about the servlet into the interface when you first implement it.

+2


source







All Articles