ASP.NET Output Cache Provider Overview
To configure NCache as ASP.NET Output Cache Provider, please follow the steps below:
Prerequisites
- To configure ASP.NET Output Cache Provider install the following NuGet packages in your application based on your NCache edition:
- Enterprise: AspNet.OutputCache.NCache
- Professional: AspNet.OutputCache.NCache.Professional
- To utilize the extension, include the following namespaces in your application in Startup.cs:
- The cache must be running.
- For API details, refer to: NOutputCacheProvider, GetByTag.
- Make sure that the data being added is serializable.
- To ensure the operation is fail-safe, it is recommended to handle any potential exceptions within your application, as explained in Handling Failures.
- To handle any unseen exceptions, refer to the Troubleshooting section.
Step 1: Register NCache as ASP.NET Output Cache Provider
To register NCache as ASP.NET Output Cache 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="demoCache"
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
Following are the ASP.NET Output Cache Provider configuration members:
Members | Description |
---|---|
cacheName |
Specifies the name of the cache that has been configured through NCache Management Center. The application will use this cache for caching specified pages. It requires a String parameter and if no cache name is specified, a configuration exception will be thrown. |
exceptionsEnabled |
It is an optional Boolean attribute that specifies whether exceptions from cache API are propagated to the page output. Setting this flag True is especially helpful during the development phase of the application since exceptions provide more information about the specific causes of failure. The default value is False. |
enableLogs |
It is an optional Boolean attribute. When this flag is set to True, all important events are logged including exceptions, cache initialized, disposed, and session not found, etc. The default value is False. |
enableDetailLogs |
It is an optional Boolean attribute. When this flag is set to True, the information that is useful for debugging purposes will be included in the logs. The default value is False. |
Step 2: Add ASP.NET Output Cache Tag To Specific Pages
Add the below mentioned OutputCache
tag to those pages whose output you want to cache. Its duration is specified in seconds.
<%@ OutputCache VaryByParam="ID" Duration="300">
Fetch Output Cache Data
Note
Tags are only available in NCache Enterprise.
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.SearchService.GetByTag(new Tag("NC_ASP.net_output_data"));
See Also
Using Output Cache with Custom Hooks
View State Caching
ASP.NET Core
Alachisoft.NCache.OutputCacheProvider