You could use the ASP. NET session to store per user values.
Up vote 0 down vote favorite share g+ share fb share tw.
On each controller call I have a code that gets some user properties from a webservice. I want to cache these for each user so I only hit the webservice once. What is the best way to cache code in a controller method so it will allow me to avoid hitting the database on every URL request but also not cache one users info when another user logs on?
Asp. Net-mvc caching link|improve this question asked Oct 30 '10 at 13:58leora1,48227145360 95% accept rate.
Check out the caching piece of the Enterprise library. We use it at work to cache lookups, so you only hit our WCF services once, instead of thousands of times for the exact same data. You can also use Session, which I highly advise against unless your user is very small.
If (Session("user") == null) { Session("user") = CallWebService. GetUser(userId); } Why you should keep Session small, for this webpage: Avoid storing too much data in session variables, and make sure your session timeout is reasonable. This can use a significant amount of server memory.
Keep in mind that data stored in session variables can hang out long after the user closes the browser. Too many session variables can bring the server on its knees.
This seems like a bit of overkill. Is there not a simpler solution (an attribute or something) to say cache per user? ) – leora Oct 30 '10 at 14:17 @ooo - I edited it for another option, using Session – Martin Oct 30 '10 at 14:38 what is the reason you advise against using session?
What do you mean unless your "user" is very small? – leora Oct 30 '10 at 16:50.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.