Jump to content


NHibernate Cache not caching objects


  • Please log in to reply
3 replies to this topic

#1 Guest_reach4thelasers_*

Guest_reach4thelasers_*
  • Guests

Posted 24 March 2009 - 12:32 PM

I've been having problems getting NCache to work with NHibernate. If the cache is not running my app barfs saying that no cache was found, but then when start the cache and run my app none of the performance counters increase to indicate that the cache is being used.

I can click the "add dummy data" button to add items to the cache and they get added, but nothing when my app is running.



The sections from my web.config are as follows.....

Is there a good detailed source of documentation that anyone can point me to? Or a good way of testing what the problem is, at the moment I feel like I'm walking in the dark right now, its very frustrating.

On a separate note, I am using windows 7 as my development machine, but all of the performance counters are "--" : I think this just to do with Windows7 though, i'm not sure how to switch on performance counting.

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

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=.;Database=gayzr;User ID=sa;Password=xxxxxxx;</property>

<property name="connection.isolation">ReadCommitted</property>
<property name="default_schema">dbo</property>
<property name="show_sql">true</property>

<property name='proxyfactory.factory_class'>NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>

<property name="cache.provider_class">Alachisoft.NCache.Integrations.NHibernate.Cache.NCacheProvider, Alachisoft.NCache.Integrations.NHibernate.Cache</property>

<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache">true</property>
<!-- HBM Mapping Files -->
<mapping assembly="App.Core"/>
</session-factory>
</hibernate-configuration>


<ncache>
<add key="cacheName" value="mycache"/>
<add key="enableCacheException" value="false"/>
<class name="Core.Domain.Person, App.Core">
<add key="priority" value="1"/>
<add key="useAsync" value="false"/>
<add key="relativeExpiration" value="3"/>
</class>
<class name="Core.Domain.Address, App.Core">
<add key="priority" value="1"/>
<add key="useAsync" value="false"/>
<add key="relativeExpiration" value="3"/>
</class>
<class name="Core.Domain.Photo, App.Core">
<add key="priority" value="1"/>
<add key="useAsync" value="false"/>
<add key="relativeExpiration" value="3"/>
</class>
</ncache>

#2 Guest_Kashif_*

Guest_Kashif_*
  • Guests

Posted 07 April 2009 - 09:18 AM

Could you please run the NHibernate Sample that comes with NCache and see if that works. The name of the sample is "NHibernate Integration Demo", you can find it under "Programs -> NCAche- > Samples"

Also, before you run the sample, make sure that the cache "myCache" is running or change the cache-id in the application app.config file.

In regard to the counters issue, try perfmon and access the counters using the machine name. On VISTA and Windows 2008 we have seen this issue where windows cannot access the counters using the IP addresses.

Also, try this workaround see if it helps

Select the NIC that you are using for NCache and enable "File and Printer Sharing for Microsoft Networks" protocols then see if you can access the counters.

If you still have any issues using NCache with NHibernate please send us an email on support at alachisoft along with your contact number and we'll call on right away and will resolve your issue.

Thanks,

#3 Guest_otaku_*

Guest_otaku_*
  • Guests

Posted 08 April 2009 - 10:47 AM

Another thing to check is your NHibernate mapping. I believe you have to explicitly enable second level caching in your .hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
	<class name="Class" table="Table">
  <cache usage="read-only"/>
  <!-- the rest of your mapping -->
	</class>
</hibernate-mapping>


#4 Guest_Kashif_*

Guest_Kashif_*
  • Guests

Posted 10 April 2009 - 03:16 AM

Yes, you'll have to enable the second level cache because that the caching model that NHibernate supports. You can also make direct API calls to NCache from your application instead of using it as a secondary cache.

This way you'll first check the existence of the item in the cache before making any database call and then at the end of the database call you'll update the cache if the item is new. This will also give you more control over the cache and will improve the performance.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users