NCache 4.3 - Online Documentation

View State Grouping

NCache provides a way to group view states on the basis of pages. Multiple pages can be coupled to define a new group. Each group can have a different configuration as per user's requirement. For example, a cache can be configured according to a group. You can also set a different expiration type e.g., sliding, absolute or no expiration at all for a group. Groups can also vary on maxViewStatesPerSession setting.
 
Apart from the steps described in View State Caching and Java Script Minification , you need to make the following configurations in your web.config file:
 
  • Add the property "webAppId" in settings as follows:
 
<ncContentOptimization>
<settings webAppId = "WebApp_1" enableMinification = "true" enableViewstateCaching = "true"
groupedViewStateWithSessions = "true" viewstateThreshold = "12" enableTrace = "true
maxViewStatesPerSession = "10" >
<cacheSettings cacheName = "mycache" >
<expiration type="Sliding" duration = "300"/>
</cacheSettings>
</settings>
</ncContentOptimization>
 
  • webAppId: Specifies the web application Id where the application is currently running. When webappId is specified, NCache looks up for ViewState.xml file (described below) to read configurations. If webAppId is not specified, view states will not be grouped and the default settings from web.config will be used.
 
Another important thing you need in order to group view states is a ViewState.xml file. The web application Id provided in web.config is mapped onto ViewState.xml file for loading detailed configurations. This xml will be loaded in NCache and its settings can be used to configure multiple groups of view states. The configurations provided in the web.config file are loaded as default settings and the configurations in this xml file are loaded per group. This file should be placed either in the debug folder of your application or the config folder of NCache.
 
 
  • Here is a sample ViewState.xml file:
 
<configuration>
          <viewstateConfig>
 
              <webApp webAppId="WebApp_1">
              <viewstateGroup groupId="Group_A" enableViewstateCaching="True" viewstateThreshold="12"
groupedViewStateWithSessions="false">
                    <cacheSettings cacheName="myCache" connectionRetryInterval="300"
                                  maxViewStatesPerSession="20">
                              <expiration type="Sliding" duration="5"/>
                    </cacheSettings>
                    <pages>
                    <page url="leftmenu.aspx"/><!—Relative url of a page-->
                    </pages>
              </viewstateGroup>
 
              <viewstateGroup groupId="Group_B" enableViewstateCaching="true" viewstateThreshold="23"
groupedViewStateWithSessions="false">
                    <cacheSettings cacheName="replicatedCache" connectionRetryInterval="300"
                    maxViewStatesPerSession="5" enableMetadataLocking="True" releaseLockInterval="5">
                          <expiration type="Sliding" duration="1"/>
                    </cacheSettings>
                    <pages>
                    <page url="testcaselist.aspx"/>
                    <page url="ViewState/ViewState_SessionGroup.aspx"/>
                    </pages>
              </viewstateGroup>
              </webApp>
  <webApp webAppId="WebApp_2">
                <viewstateGroup groupId="Group_A" enableViewstateCaching="True" viewstateThreshold="2"
groupedViewStateWithSessions="false">
                    <cacheSettings cacheName="cache" maxViewStatesPerSession="20">
                    <expiration type="Sliding" duration="2"/>
                    </cacheSettings>
                    <pages>
                    <page url="menu/viewstate.aspx"/>
                    </pages>
                </viewstateGroup>
                </webApp>
 
          </viewstateConfig>
</configuration>
 
  • webAppId(compulsory): Used to distinguish multiple web app sections.
  • GroupId(compulsory): Used to distinguish multiple groups.
  • enableViewstateCaching: Enable/disable the ViewState caching.
  • viewstateThreshold: Sets minimum threshold size of view state in bytes. ViewStates which are smaller than threshold value will not be cached.
  • gropuedViewStateWithSessions: Through this property you can group session with view state. All the view state for a session is grouped with Session id. This allows end user to  retrieve all view state grouped with a Session id from the cache with group information. Set this property to "true" is order to enable grouped view state with sessions. By default this attribute is false.
  • viewstateThreshold: Sets minimum threshold size of view state in bytes. ViewStates which are smaller than threshold value will not be cached.
  • cacheName: Name of the cache.
  • ConnectionRetyInterval: Time interval between each retry connection to cache.
  • maxViewStatesPerSession: Through this property user can limit the number of view states being cached per session, in order to control cache use. If a session is very long and all the view states are being cached, it can affect cache consumption. View states can be grouped with sessions or cached independently. To enable this feature, specify any value greater than zero for this property. For a value of zero or less, all view states will be cached.
  • expiration type: Sets the expiration type which can either be Sliding, Absolute or None.
  • duration: Sets expiration interval in minutes.
  • page url: Relative url of a page.
 
          Please note that:
 
  1. The xml file can have multiple web app configurations. In each web app configuration there can be one or more group configurations.
  2. All the web pages for a certain group are provided in <pages> section and page url is relative url of a page.
  3. If a page configuration is not found in View State configuration file, default settings provided in web.config will be used.
  4. If any property is missing for any group, default property value provided in web.config will be used.
  5. Different caches can also be configured for different groups.
 
 
See Also

 
 
 
 
 
     
 
© Copyright  2014 Alachisoft. All rights reserved.