Configuring and Using NCache Content Optimization
Configure View State Content Optimization
The following steps need to be performed in order to use content optimization feature of NCache with View State:
Step 1: Configure App_Browser File
Create an App_browser file in the ASP.NET application. It will be created under the directory of App_browsers.
Now plug page adapters in the app_browser file as following:
<browsers>
<!-- NCache Plug page adapters in the app browser file as following:. -->
<browser refID="Default">
<controlAdapters>
<adapter controlType="System.Web.UI.Page"
adapterType="Alachisoft.NCache.Adapters.PageAdapter">
</controlAdapters>
</browser>
</browsers>
Step 2: Configure Web.config File
Add the assembly reference for Alachisoft.NCache.Adapters
(located in [InstallDir]\integrations\ContentOptimization) in <compilation>
section of Web.config:
Enterprise Edition:
<compilation defaultLanguage="c#" debug="true" targetFramework= "4.0">
<assemblies>
<add assembly="Alachisoft.NCache.Adapters, Version=x.x.0.0, Culture=neutral, PublicKeyToken=CFF5926ED6A53769">
</assemblies>
</compilation>
Professional and Open Source Editions:
<compilation defaultLanguage="c#" debug="true" targetFramework= "4.0">
<assemblies>
<add assembly="Alachisoft.NCache.Adapters, Version=x.x.x.x, Culture=neutral, PublicKeyToken=1448e8d1123e9096">
</assemblies>
</compilation>
Note
Replace Version=x.x.x.x
with the actual NCache version that you have installed. For example, Version=4.6.0.0
.
- Register the configuration section for View State in Web.config of your application:
<configSections>
<sectionGroup name="ncContentOptimization">
<section name= "settings"
type="Alachisoft.NCache.ContentOptimization.Configurations.ContentSettings"
allowLocation="true"
allowDefinition= "Everywhere">
</sectionGroup>
</configSections>
- Specify the settings for the registered config section:
<ncContentOptimization>
<settings enableViewstateCaching="true"
viewstateThreshold="1"
cacheUriMapping="true"
enableTrace="false" >
<cacheSettings cacheName="demoClusteredCache" connectionRetryInterval="300">
<expiration type="Absolute" duration="1" >
</cacheSettings>
</settings>
</ncContentOptimization>
Configuration Members
Member | Description |
---|---|
enableViewstateCaching |
Boolean value to enable /disable the View State caching. |
viewstateThreshold |
Sets the minimum threshold size of viewstate in bytes. Viewstates which are smaller than threshold value will not be cached. |
cacheUriMapping |
Cache URL mapping, Default is true. |
enableTrace |
Enable/disable traces. |
cacheName |
Name of the Cache. |
connectionRetyInterval |
Retry Connection to Cache interval. Default is 300 seconds. |
Expiration |
Sets the expiration type which can either be Sliding , Absolute or None . And also expiration interval in minutes. |
Duration |
Sets expiration interval in minutes. |
Fetch View State Data
If the same cache is being used for View State caching and other data, View State
data can be retrieved by NC_ASP.net_viewstate_data
tag. With this tag it is
easy to find the data specific to View State.
Hashtable allViewStateData = cache.GetByTag(new Alachisoft.NCache.Runtime.Caching.Tag("NC_ASP.net_viewstate_data"));
The viewstate
of a particular session can easily be retrieved from cache based
on sessionId
.