ASP.NET Output Cache is a mechanism provided by Microsoft that allows you to keep an in-memory copy of the rendered content of the ASP.NET page. Due to this, ASP.NET can serve the subsequent user requests for this page from an in-memory cached copy instead of re-executing this page which can be quite expensive due to heavy database calls.
Therefore, ASP.NET Output Cache not only improves your application performance but also reduces expensive database trips. This improves your ASP.NET application scalability because otherwise, the database would become a scalability bottleneck if all those ASP.NET pages were executed again and again.
But, ASP.NET Output Cache resides in your ASP.NET worker process address space where worker process resets or recycles quite frequently. When that happens, all the ASP.NET Output Cache is lost. Secondly, in the case of a web garden, the same page output is cached multiple times, once in each worker process consuming a lot of extra memory.
NCache Details NCache Docs ASP.NET Output Cache
Also read: ASP.NET Output Cache in Microsoft Azure to Improve Performance
Using NCache as Distributed Cache for ASP.NET Output Cache
To overcome these limitations of ASP.NET Output Cache, NCache has implemented an ASP.NET Output Cache provider to enable the caching of ASP.NET rendered output in out-of-process cache instead of worker process address space. This way, the output of your rendered ASP.NET page is available to all other web servers in the web farm without even rendering the same ASP.NET page locally in each worker process.
By using NCache as an ASP.NET Output Cache provider you can not only cache more data in the out-proc cache but can also dramatically reduce the load on your database. This is because each rendered ASP.NET page output is accessible to all web servers in the web farm without executing the page rendering process in each worker process which involves expensive database trips.
Furthermore, NCache gives you the flexibility to even cache the output of certain parts of your ASP.NET page instead of the complete page. This approach is very helpful in scenarios where you want certain parts of your ASP.NET to render each time. In addition, NCache also provides you high availability because even if your worker process resets or recycles, your data is not lost as it is not part of your worker process address space and resides on separate caching servers.
Steps to Configure NCache Output Caching Provider
Step:1 Register NCache as ASP.NET Output Cache Provider
Modify your ASP.NET application’s web.config to register NCache output caching provider as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<caching> <outputcache defaultprovider="NOutputCacheProvider"> <providers> <add name="NOutputCacheProvider" type="NCOutputCache.NOutputCacheProvider" exceptionsenabled="true" enablelogs="false" cachename="mypartitionofReplicaCache"> </add></providers> </outputcache> </caching> <compilation debug="true" targetframework="4.0"> <assemblies> <add assembly="Alachisoft.NCache.OutputCache, Version=4.1.0.0, Culture=neutral"> </add></assemblies> </compilation> |
Step: 2 Add ASP.NET Output Cache tag
Add the under-mentioned Output cache tag to those pages whose output you want to cache.
1 2 |
<%@ OutputCache VaryByParam="ID" Duration="300" %> |
Also, ASP.NET versions earlier than ASP.NET 4.0 do not provide support of custom ASP.NET Output Cache providers. Therefore, to support all earlier versions of ASP.NET, NCache has also implemented another version of ASP.NET Output Cache provider using an HttpModule. This HttpModule based on ASP.NET Output Cache provider by NCache enables you to use distributed cache to store rendered ASP.NET page output, even if your application is using ASP.NET versions earlier than 4.0.
Conclusion
In summary, by using NCache output caching provider you can easily boost your ASP.NET application response time and can reduce database load. So, get your gears ready and start using NCache for a much faster and reliable experience!
NCache Details Download NCache Edition Comparison
Set the conf to contain the location for localized archives. Used by internal DistributedCache code.