NCache 4.6 - Online Documentation

How to Configure Cache Regions

NHibernate uses cache regions to store objects. NCache allows cache regions to be configured with different properties. For this purpose NCache has a configuration file named "NCacheNHibernate.xml", which contains all regions’ configurations and other related configurations used by NCache. This file can be placed at root directory of application or in config folder of NCache Installation directory.
Following is a sample configuration file:
<application-config application-id="myapp" enable-cache-exception="true"
default-region-name="default" key-case-sensitivity="false">
          <region name="AbsoluteExpirationRegion" cache-name="mycache" priority="Default" expiration-type="sliding" expiration-period="180" />
          <region name="default" cache-name="mycache" priority="default" expiration-type="none" expiration-period="0" />
          <dependency entity-name="nhibernator.BLL.Customer" type="oledb" sql-statement="select ContactName from dbo.Customers where CustomerID =?" cache-key-format="depdency.customer:[pk]"/>
Multiple application configurations can be specified in NCacheNHibernate.xml. Any NHibernate application will use one of the specified configuration based on the application-id specified in applications app.config/web.config file.
Following are the configurable options in application-config section.
This option let the user specify a unique ID for current application-config. This id is used to select appropriate configuration for a particular application.
Identifies whether the exceptions if occurred in NCache will be propagated to NHibernate provider.
Allows to specify a default region for the application. If a particular region's configurations are not found, default region configurations will be used. Specified default region configuration must exist in cache-regions section.
This option allows to specify whether cache keys will be case sensitive or not. This option has to be configured according to database used. If database is case-sensitive set this option true, otherwise false.
This sections lets the user configure multiple cache regions for NHibernate application. Each region's configuration is specified in region tag.
This tag contains the configurations for one particular region. Following options can be configured for any particular region.
name: Each region is identified by its name. Name of the region should be unique.
cache-name: This option allows specifying  NCache's cache name to be used for this region.
priority: The priority the user wants to use for cached items. The possible values are :
·     Default
·     Low
·     BelowNormal
·     Normal
·     AboveNormal
·     High
·     NotRemovable
expiration-type: This options allows to specify type of expiration for any item in this region. Possible values are absolute/sliding/none.
expiraion-period: Allows to specify expiration period if absolute/sliding expiration is configured. Its value should be greater than 0.
Lets the user specify database dependencies for current NHibernate application.
dependency: Each dependency is configured in a dependency tag. Multiple tags can be configured for multiple dependencies. The following options can be configured for each dependency.
entity-name: Dependencies are added based on the fully qualified name of classes. This option allows to specify name of class for which current dependency is to be added. Any entity can have maximum one dependency.
type: Allows to specify database dependency type. Possible values are sql/oracle/oledb. Since NCache provider uses connection string specified in NHibernate's configuration, use dependency type appropriate to connection string.
sql-statement: Allows to specify sql statement to be used for building NCache's database dependency.
cache-key-format: This option is used to configure cache key format for any item of current entity type. Cache key format should include "[pk]" in it, which will be replaced with the primary key of record. cache-key-format may also include "[en]" which will be replaced with entity name. Default value of cache key format is "NHibernateNCache:[en] #[pk]". Same cache key format should be used while writing database trigger incase of OLEDB database dependency. See NCache help for writing database trigger for OLEDB dependency.
composite-key-separator: If the records of current entity have composite key as primary key, cache-key is formed by combining all keys separated by composite-key-separator. composite-key-separator must be of one character length. Its default value is "$".
See Also