NCache 4.6 - Online Documentation

How to Configure NHibernate Application

 
  • In NHibernate configuration, configure NCache as NHibernate's second level cache provider by adding the following property.
 
<property name="cache.provider_class"> Alachisoft.NCache.Integrations.NHibernate.Cache.NCacheProvider,      Alachisoft.NCache.Integrations.NHibernate.Cache</property>
 
cache.provider_class: This option lets the user specify NCache as Second level cache provider. The user needs to mention two classes which implement ICacheProvider and ICache interfaces respectively. This is how NHibernate knows how to call this second level cache.
 
  • Place NCache‚Äôs NHibernate provider dll Alachisoft.NCache.Integrations.NHibernate.Cache.dll located at %NCacheInstallDir%/integration/nhibernate/assembly/ in application's base directory.
 
  • Enable the use of second level cache in application by adding the following property in NHibernate configuration section's session-factory tag:
 
<property name="cache.use_second_level_cache">true</property>
 
  • NCache provider for NHibernate identifies each application by an application ID that is later used to find the appropriate configuration for that application from NCache configuration file for NHibernate "NCacheNHibernate.xml". This application ID must be specified in application's configuration file (app.config/web.config). Add following property in application configuration for this purpose:
 
<appSettings>
      ....
    <add key="ncache.application_id" value="myapp" />
      ....
  </appSettings>
 
 
See Also