ASP.NET Output Caching with NCache
NCache has implemented an ASP.NET Output Cache provider to enable the caching of ASP.NET rendered output in out-of-process (out-proc) 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.
Furthermore, NCache as ASP.NET Output Cache provider gives you the flexibility to even cache the output of certain parts of your ASP.NET page instead of the complete page, making useful data more manageable and precise.
Step 1: Register NCache as ASP.NET Output Cache Provider
In Web.config of your application, under the section of system.web
element
add NCache provider as a default provider.
For Enterprise Edition:
<!-- 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="demoClusteredCache"
exceptionsEnabled="false"enableDetailLogs="false"
enableLogs="true"
writeExceptionsToEventLog="false"/>"
</providers>
</outputCache>
</caching>
For Professional and Open Source Editions:
<!-- 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=1448e8d1123e9096"
cacheName="demoClusteredCache"
exceptionsEnabled="false"enableDetailLogs="false"
enableLogs="true"
writeExceptionsToEventLog="false"/>"
</providers>
</outputCache>
</caching>
Note
Replace Version=x.x.x.x
with the actual NCache version that you have installed. For example, Version=4.6.0.0
.
Step 2: Add ASP.NET Output Cache Tag To Specific Pages
Add the under mentioned OutputCache
tag to those pages whose output you want to
cache. Duration
is specified in seconds.
<%@ OutputCache VaryByParam="ID" Duration="300">
Fetch Output Cache Data
Output cache data can be retrieved by NC_ASP.net_output_data
tag. With this
tag, it is easy to find data specific to output caching data.
Hashtable allOutputCacheData = cache.GetByTag(new Alachisoft.NCache.Runtime.Caching.Tag("NC_ASP.net_output_data"));