NCache 4.3 - Online Documentation

Step 3: Enable DBCacheDependency in NHibernate

To enable Database Cache Dependency in nhibernate items, you need to define <database-dependencies> configuration section in the application's configuration file (it could be app.config file if its a desktop application or web.config file if its a web application) and enable database notifications in the database.
To enable DBCacheDependency in NHibernate, do the following:
  1. Provide dbSync type in <database-dependencies> section as follows:
<application-config application-id="myapp" enable-cache-exception="true" default-region-name="default" 
  <region name="AbsoluteExpirationRegion" cache-name="myCache" priority="Default" expiration-type="sliding"
  <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]"/>
The type of database dependency is either "sql", "oracle", "oledb". sql is a mechanism for synchronizing your cache with SQL Server 2005 database through .NET events. oledb allows you to synchronize your cache with any OLEDB compliant database through a configurable polling interval. If you specify "sql" value, then you must also specify the  sql-statement="...". You specify a "select" SQL statement to identify a row in SQL Server 2005 database that corresponds to this cached item. Then, whenever that row is updated or removed, this cached item is also removed.
  1. Enable database notifications on the database except when you are using SQL Server 2005. For further details see Enabling Database Notifications for SQL Server, Enabling Database Notifications for Oracle and Enabling Database Notifications for DB2.
    See Also

© Copyright  2014 Alachisoft. All rights reserved.