ASP.NET Output Cache Provider Overview
In order to configure NCache Output Caching Provider, please follow the steps below:
- Install the following NuGet packages in your application based on your NCache version:
- 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
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>
Replace Version=x.x.x.x with the actual NCache version that you have installed.
||Specifies the name of the cache that has been configured through NCache Manager. The application will use this cache for caching specified pages. It requires a
||It is an optional
||It is an optional
||It is an Optional
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. It's duration is specified in seconds.
<%@ OutputCache VaryByParam="ID" Duration="300">
Fetch Output Cache Data
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"));