How to Quickly Use NCache with NHibernate?

Using NCache with your NHibernate application is a multi-step process.

1. Install and configure NCache on app servers

Installing and configuring NCache can be summarized into these steps:

  1. Install NCache on all app server & cache servers
  2. Create a cache cluster
  3. Configure remote clients
  4. Test the cache cluster
  5. For more details, watch a 7-minute NCache video on Five Steps to Getting Started.

2. Configure NCache as Level-2 Provider

To enable NCache as Level-2 provider for NHibernate, add the following lines to your app.config or web.config file:

<hibernate - configuration> 
    <session - factory> 
    <property name = "cache.provider_class"> 
    </session - factory> 
</hibernate - configuration> 

3. Specify NCache properties for NHibernate

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.

    <section name = "ncache" 
    type = "Alachisoft.NCache.Integrations.NHibernate.Cache.NCacheSection, 

The above lines specify an "ncache" section for your config file. Now specify NCache properties in this "ncache" section.

    <!--default regionis  used if  no other regions are specified.-->
    <region name = " default ">
        <add key = " cacheName "  value = " myCache " />
        <add key = " enableCacheException "  value = " false " />
    <!--see docs for  custom regions  &  db - synchronization properties.-->

There are more NCache properties if you want to synchronize the cache with your database. See product documentation for more details.

What to Do Next?

© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.