I have my SaaS application
And whenever the my user access, he need identify the Company that it belongs, for query in Database
SELEC * from table where CompanyId = CompanyActive.Id
If I use Session, will occupy a lot of server memory, up to 1000 users are active simultaneously
There is also the problem that if the user has allowed saving password, or your login session has not expired, to access the Session, it will be Null
Currently do as follows:
The user makes the login and sets the Company for Session and also set a value in Claim
All my Controllers, use BaseController, and all the requests, check if the Session is null, if it is Null, I get the value of the Claim, again get the object and step in Session
What better way for me to do this?
Cause I need some more information of the Company, for example:
Id, Name, Folder, Container
1. Add the Company records in cache on application start as they are not much
2. Cache the user records in on application start
3. on a user login, update user chache record with a flag as loggedin=true (property of user record)
4. write a wrapper class to access the cache records.
5. To get company id of current logged in user. go cache user record find company id