ASP.NET Output Cache Provider Overview
Note
This feature is only available in NCache Enterprise and Professional editions.
In order to configure NCache Output Caching Provider, please follow the steps below:
Pre-requisites
To utilize Output Cache Provider in your application:
Install the AspNet.OutputCache.NCache (Enterprise/Professional) NuGet package to your application by executing the following command in the Package Manager Console:
For Enterprise
Install-Package AspNet.OutputCache.NCache
For Professional
Install-Package AspNet.OutputCache.NCache.Professional
Also include the following namespace in your application before starting:
- Alachisoft.NCache.OutputCacheProvider.dll
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 i.e.
<!-- 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>
Note
Replace Version=x.x.x.x with the actual NCache version that you have installed.
Configuration Members
Members | Description |
---|---|
cacheName |
Requires string parameter. Specifies the name of the cache that has been configured through NCache Web Manager. The application will use this cache for caching specified pages. If no cache name is specified, a configuration exception will be thrown. |
exceptionsEnabled |
Optional Boolean attribute. Specifies whether exceptions from cache API are propagated to the page output. Setting this flag is especially helpful during development phase of application since exceptions provide more information about the specific causes of failure. The default value is false . |
enableLogs |
Optional Boolean attribute. When this flag is set, all important events are logged including exceptions, cache initialized, disposed, and session not found etc. The default value is false. |
enableDetailLogs |
Optional Boolean attribute. When this flag is set, the information that is useful for debugging purposes will be included in logs. The default value is false . |
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
Note
Tags are only available in NCache Enterprise and editions.
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 Tag("NC_ASP.net_output_data"));
See Also
Using Output Cache with Custom Hooks
View State Caching
ASP.NET Core