ASP.NET Output Cache, (provided by Microsoft), allows you to store an in-memory copy of the rendered content of the ASP.NET page. This allows ASP.NET to serve subsequent user requests from the cached copy instead of re-executing the page, which can be resource-intensive due to heavy database calls. By utilizing the ASP.NET Output Cache, you can significantly enhance your application performance and reduce expensive database trips, thereby improving the scalability of your ASP.NET application. This prevents the database from becoming a bottleneck, if all the ASP.NET pages are executed repeatedly.
Unfortunately, since the ASP.NET Output Cache resides in your ASP.NET worker process address space, where worker process is quite frequently reset or recycled. When that happens, all the data is lost. Secondly, in a web garden, the same page output is cached multiple times, once in each worker process consuming extra memory. To address the limitations of ASP.NET Output Cache, NCache offers an advanced solution by storing rendered ASP.NET output in an out-of-process cache rather than in the worker process address space.
Using NCache as Distributed Cache for ASP.NET Output Cache
The NCache ASP.NET Output Cache makes cached output accessible across all web servers in the farm, eliminating redundant page rendering and reducing database load. By using NCache as an ASP.NET Output Cache provider, you can significantly expand your caching capacity and improve performance, as rendered page outputs are efficiently shared among servers, minimizing repetitive database queries. Moreover, NCache offers caching flexibility, allowing you to cache specific parts of your ASP.NET page rather than the entire page. This is especially useful for scenarios where certain elements need to be dynamically rendered. In addition, NCache offers you high availability by storing cache data on separate servers, protecting it from being lost during worker process resets or recycles.
Steps to Configure NCache Output Caching Provider
Follow the steps below to configure the NCache Output Caching Provider:
Step:1 Register NCache as ASP.NET Output Cache Provider
Modify your ASP.NET application’s web.config to register the provider as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<!-- caching section group --> <caching> <outputcache defaultprovider="NOutputCacheProvider"> <providers> <add name="NOutputCacheProvider" type= "Alachisoft.NCache.OutputCacheProvider.NOutputCacheProvider, Alachisoft.NCache.OutputCacheProvider, Version=x.x.x.x, Culture=neutral, PublicKeyToken=cff5926ed6a53769" cacheName="demoCache" exceptionsEnabled="false" enableDetailLogs="false" enableLogs="true" writeExceptionsToEventLog="false"/>" </providers> </outputcache> </caching> |
Step: 2 Add ASP.NET Output Cache tag
Add the tag mentioned below to the pages whose output you want to cache.
1 |
<%@ OutputCache VaryByParam="ID" Duration="300"> |
ASP.NET versions older than 4.0 do not support ASP.NET Output Cache providers. To overcome this, NCache provides an alternative implementation using the HttpModule-based provider. This HttpModule (based on ASP.NET Output Cache provider) enables you to use a distributed cache to store rendered page output, even with earlier versions of ASP.NET. This ensures compatibility and extends the benefits of distributed caching to applications running on older ASP.NET versions.
Conclusion
Integrating NCache Output Caching Provider can easily boost your ASP.NET application’s response time and reduce database load. So, start using NCache for a much faster and reliable experience, optimizing both performance and scalability for your application!
Set the conf to contain the location for localized archives. Used by internal DistributedCache code.