I’m just learning ASP.net and also making a web app for a friend in the same.
Now, in my app, there is a table that maps users to company’s branches, and another to map branches to clients. When the user logs in, I make fire a query to get a list of the branches he/she has access to, and then another one to get all the list of clients that he is responsible for. This happens a lot of times and is required on many pages.
Also, I’m using DevExpress’ GridView and GridViewLookUp tools. If you’re familiar with them, they are just like GridView in ASP.net and cause a postback each time the displayed entries are sorted or a different page is selected for viewing the entries. Basically, I want to to know that I have to fire the above two queries a lot of times.
There are on an average 100-150 clients that a user is usually responsible for.
So what I want to know is, for a number that high, should I retrieve all the client names and store them in a session so that I don’t have to connect to the database again as long as the user is logged in? Or should I just keep it the way it is and let it find clients every time from the database?
Since this data is specific for the Logged in user, you can keep it in the
Sessionvariable. Another alternate option is to implement aCachelayer in between your UI/Business logic and Data Access. Query it once a day (or your defined interval- cache duration) and keep it in theCache. and next time when your UI requires it get it from there. If the data is null, that means cache is expired. Query it again and store it. Cache data is global to all users while session data is specific to that user session.If you have so many requests coming in, Keeping a copy of 150 client objects (how big it is ?) in session for each requests seems a little bad approach compared to keeping it in Cache. So i think You should go for Cache layer option.