Caching user data to avoid excessive database moves

After creating a proof of concept for the ASP.NET MVC site and ensuring proper separation of problems, I noticed that I was making a lot of costly redundant database queries for current user information.

Being historically desktop staff and services, my first thought was to cache db results in some static s. There have not been many searches to make sure that this will save current user data throughout the AppDomain for all users.

Then I thought about using HttpContext.Current . However, if you put the material here when the user logs out, then when you enter your cached data it will be outdated. I could update this every time I log in / out, but I can’t say if this is correct. In the absence of other ideas, this is where I bow.

What is an easy way to cache user details accurately and don’t need to make tons of database calls?

+7
database caching asp.net-mvc
source share
3 answers

If the information you want to cache is for each user, and only while they are active, then the session is the right place.
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.aspx

+5
source share

What you are looking for is System.Web.Caching.Cache

http://msdn.microsoft.com/en-us/library/system.web.caching.cache.aspx

+2
source share

ASP.NET session state management is good for some situations, but when loading a large load, it aims to create bottlenecks in ASP.NET performance. Read more about this here:

http://msdn.microsoft.com/en-us/magazine/dd942840.aspx

http://esj.com/articles/2009/03/17/optimize-scalability-asp-net.aspx

The solution to avoiding bottlenecks is to use distributed caching. There are many free distributed caching solutions on the market, such as Memcached or NCache Express.

I don’t know much about Memcached, but I used Alachisoft's NCache Express, it allows you to use ASP.NET caching without requiring code changes.

+2
source share

All Articles