If your ASP.NET application only has a few users, you probably don’t care how fast or slow it is and it is probably giving you pretty good performance anyway. But, as you add more load to your ASP.NET application, the chances are quite high that ASP.NET performance will drop significantly. It might even grind to a halt if enough load is put on it. And, ironically, all of that happens just when your business is seeing more activity so the impact is even greater.
ASP.NET today has become really popular for high traffic apps and it is now common to see 10-20 server load balanced web farms and in some cases even 50-100 server farms. So, in these situations, ASP.NET performance is even more sensitive issue to resolve.
NCache Details NCache Docs ASP.NET Caching Docs
Using NCache as a Distributed Cache
The main reason for ASP.NET performance drops as you increase load on it is your database which cannot handle larger loads the way your ASP.NET application web farm can. This is because you can add more servers to the ASP.NET web farm but you cannot do the same with your database.
So, in these situations, your best bet is to use a distributed cache like NCache. NCache is in-memory so it is much faster than the database. And, NCache builds a cluster of cache servers and you can grow the cluster linearly just like the web farm. As a result, with NCache, your ASP.NET performance remains great even under extreme transaction loads. You can use NCache in the following two ways:
ASP.NET Session State Storage
You can configure your ASP.NET application to store ASP.NET Session State in NCache instead of InProc, State Server, or SQL Server. Please note that no programming is needed here. You only modify web.config code as following:
1 2 3 4 5 6 |
<sessionstate cookieless="false" regenerateexpiredsessionid="true" mode="Custom" customprovider="NCacheSessionProvider" timeout="20"> <providers> <add name="NCacheSessionProvider" type="Alachisoft.NCache.Web.SessionState.NSessionStoreProvider" exceptionsenabled="true" enablesessionlocking="true" emptysessionwhenlocked="false" sessionlockingretry="-1" sessionappid="NCacheTest" useinproc="false" enablelogs="false" cachename="myReplicatedCache" writeexceptionstoeventlog="false" asyncsession="false"> <providers> <sessionstate></sessionstate></providers></add></providers></sessionstate> |
ASP.NET Application Data Cache
The other way is for you to cache application data in a distributed cache like NCache so the next time your ASP.NET application needs this data, it will find it in the cache. Here is a small code sample on how to cache application data:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
using Alachisoft.NCache.Web.Caching; ... Cache cache = NCache.InitializeCache("myCache"); // Create a key to lookup in the cache // The key for will be like “Employees:PK:1000” string key = "Employee:EmployeeId:" + emp.EmployeeId.ToString(); Employee employee = (Employee)Cache[key]; if (employee == null) { // item not found in the cache. load from db LoadEmployeeFromDb(employee); // Now, add it to the cache for future reference Cache.Insert(key, employee, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Default, null ); } |
The more data you cache, the less you have to go to the database and the faster is your ASP.NET application performance.