Using NCache with your NHibernate application is a multi-step process.
Installing and configuring NCache can be summarized into these steps:
For more details, watch a 7-minute NCache video on Five Steps to Getting Started.
To enable NCache as Level-2 provider for NHibernate, add the following lines to your app.config or web.config file:
1 <hibernate-configuration> 2 ... 3 <session-factory> 4 ... 5 <property name="cache.provider_class"> 6 Alachisoft.NCache.Integrations.NHibernate.Cache.NCacheProvider, 7 Alachisoft.NCache.Integrations.NHibernate.Cache 8 </property> 9 </session-factory> 10 </hibernate-configuration>
Now that you've configured NCache to become a Level-2 provider for NHibernate, you need to provide some NCache specific properties. These properties help NCache work with your application.
1 <configSections> 2 ... 3 <section name="ncache" 4 type="Alachisoft.NCache.Integrations.NHibernate.Cache.NCacheSection, 5 Alachisoft.NCache.Integrations.NHibernate.Cache"/> 6 </configSections>
The above lines specify an "ncache" section for your config file. Now specify NCache properties in this "ncache" section.
1 <ncache> 2 <!—"default" region is used if no other regions are specified. --> 3 <region name="default"> 4 <add key="cacheName" value="myCache"/> 5 <add key="enableCacheException" value="false"/> 6 </region> 7 8 <!— see docs for custom regions & db-synchronization properties. --> 9 </ncache>
There are more NCache properties if you want to synchronize the cache with your database. See product documentation for more details.