From my general understanding I believe UserContext for a web application is supposed to hold user authentication and authorization (user roles) information.
As part of user roles, there are definitions on who can access what data and accordingly the corresponding reference data is loaded into the UserContext as well.
Is this a good practice to load and use reference data from UserContext? Does this have any impact with the number of sessions vs size of data it is holding inside JVM?
I am thinking we use UserContext only for authentication and authorization but load the reference data from cache on demand and use it if required.
This is always a trade off of how much space you’re taking up in the session. How big is your reference data? Generally speaking, unless it’s small I’d use the caching approach you described.
DOn’t forget that user sessions can be shared across clusters etc as well, so generally speaking keeping them small is a good thing.