Alachisoft NCache 4.1 - Online Documentation

Using Output Cache

 
NOTE: This feature is not available in NCache Express and Professional edition.
 
NCache provides extremely fast and reliable output caching feature for ASP.NET applications running in web farm environment, where regular output caching fails. Once a page is rendered by any of the web server in the web farm, it is available to all other servers due to clustered cache created by NCache. Your cached pages are highly available because clustered cache gives no single point of failure.
Steps to plug-in NOutputCache to your existing web applications are as follows:
 
  1. Register NOutputCache as the httpmodule inside <system.web> in web.config file.
     
    <httpModules>
    <add name = "Alachisoft.NCache.Web.NOutputCache" type = "Alachisoft.NCache.Web.NOutputCache.NOutputCache, Alachisoft.NCache.OutputCache, Version=x.x.x.x, Culture=neutral, PublicKeyToken=cff5926ed6a53769"/>
    </httpModules>
     
    Note: Replace version “x.x.x.x” with the actual NCache version that you have.
     
     
  2. Register 'ncache' configuration section in the <configSections> of the web.config as follows:
     
    <configSections>
    <section name = "ncache"
    type = "Alachisoft.NCache.Web.NOutputCache.NCacheSection, Alachisoft.NCache.OutputCache, Version=x.x.x.x, Culture=neutral, PublicKeyToken=cff5926ed6a53769"/>
    </configSections>
     
  3. Then add actual <ncache> section in <configuration> section of web.config holding information of pages to be cached.
     
    <ncache>
    <outputCacheSettings cacheName = "myReplicatedCache" clientCacheName = "" exceptionsEnabled = "true" logsEnabled = "false" enableDetailLogs = " false" enableClientCacheSync = "false">
    <outputCachePages>
    <add name = "/main.aspx" enabled = "true" requestType = "post" duration = "20" varyByParam = "cbxCustomerName" varyByHeader = "Connection" varyByCustom = "browser"/>
    </outputCachePages>
    </outputCacheSettings>
    </ncache>
     
    <ncache> section holds the following configurable options:
     
  • outputCacheSettings: Lets you specify cache settings for output caching.
  • cacheName: Required string attribute. Specifies the name of the cache that you have configured through NCache Manager. Your application will use this cache for caching specified pages. If no cache name is specified, a configuration exception will be thrown.
  • clientCacheName: Optional string attribute. Specifies client cache name which will enable client cache feature of NCache.
  • 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 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 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 is false.
  • enableClientCacheSync: If client cache is specified and this option is set to 'true', output cache will use Cache Sync Dependency feature of NCache to synchronize both level1 and level2 caches. On the other hand, if client cache is specified and this option is set to 'false', output cache will synchronize the operations on both caches at its own. The default is false.
     
  • outputCachePages: Holds information of the pages to be cached. All the options below are page-specific.
  • name: Required string attribute. Specifies the name of the page to be cached. If no name is specified, a configuration exceptions will be thrown.
  • enabled: Optional Boolean attribute. Specifies whether caching for the specified page is enabled or not. The default is true.
  • requestType: Optional string attribute. It is type of request for which page will be cached. It can be 'get', 'post' or 'get/post'. If no request type is specified page will be cached for only 'get'.
  • duration: Required integer attribute. Specifies duration (in seconds) after which the page will be expired from cache and upon next request it will be re-executed and cached again. If no duration is specified, a configuration exception will be thrown
  • varyByParams: Optional string attribute. Different versions of page output will be cached for each request that arrives with a different parameter(s) value. varyByParam specifies these parameters. Provide multiple parameters in the form of comma separated string. To vary by all parameters, use ' '. If no string is specified, page caching will not vary by parameters.
  • varyByHeader: Optional string attribute. To vary page caching by http headers, provide comma separated headers. To vary by all headers, use ' '. If no string is specified, page caching will not vary by headers.
  • varybyCustom: Optional string attribute. Provide if you wish to vary page caching by custom values. You cannot specify multiple custom strings using comma, they will be treated as one variable. The only custom string provided by ASP.NET is 'browser'. If you wish to provide your own custom string, you must override GetVaryByCustomString() method in Global.asax.
 
See Also
 

 
Copyright © 2005-2012 Alachisoft. All rights reserved.