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.
Key Takeaways
Prevent Data Loss on Recycles: By moving the Output Cache out-of-process, cached HTML survives IIS worker process resets, ensuring that high-traffic pages do not need to be re-rendered after a server restart.
Resolve Memory Redundancy: In Web Farm and Web Garden environments, a distributed provider allows multiple worker processes to share a single cache instance, significantly reducing overall RAM consumption across the cluster.
Eliminate Database Bottlenecks: Offloading rendered page fragments to NCache prevents the back-end database from becoming a bottleneck during peak loads by serving subsequent requests directly from the distributed tier.
Configuration-Based Integration: Transitioning from the default InProc provider to a distributed model is achieved through web.config modifications, requiring no changes to the existing application source code.
| Feature | ASP.NET Default (In-Proc) | NCache (Distributed) |
|---|---|---|
| Memory Management | Causes “Memory Redundancy” | Optimized “Single-Copy” Sharing |
| Process Isolation | Tied to Worker Process | Independent Cluster Service |
| Web Farm Support | Isolated per Server | Synchronized across Farm |
| Availability | Low (Vulnerable to Recycles) | High (Data Replication) |
Why Use a 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.
How to Configure NCache as an 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 |
// 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!
Frequently Asked Questions (FAQ)
Q: How do I switch from In-Process to Distributed Output Caching?
A: To transition to a distributed model, you only need to modify your application’s web.config file. Register NCache as the default outputCache provider within the <system.web> section. This allows you to leverage an out-of-process cache without changing your existing page-level OutputCache attributes.
Q: Does using NCache require changes to my ASP.NET page code?
A: No. One of the primary advantages of this approach is that it is configuration-based. As long as your pages already use the standard <%@ OutputCache %> directive or the [OutputCache] attribute in MVC, NCache will automatically handle the storage and retrieval once the provider is registered in the configuration file.
Q: Why is a distributed cache better for “Web Gardens” than the default provider?
A: In a Web Garden (where multiple worker processes run on one server), the default provider caches the same page separately for every process, wasting significant memory. NCache provides a single, shared out-of-process storage area that all worker processes can access, eliminating this redundancy.
Q: What happens to the Output Cache if a web server in the farm fails?
A: Because NCache is a distributed, peer-to-peer cache cluster, the cached data remains highly available. If one web server fails, the cached HTML responses stay alive in the NCache cluster and can be served immediately by any other web server in the farm, preventing a sudden spike in database load.







Set the conf to contain the location for localized archives. Used by internal DistributedCache code.