views:

591

answers:

2

I've been at this for days. I have configure my web/app config to use the second level cache with a Memcached server and the provider from NHContrib. I don't get any exceptions yet in testing I see that it does not use the cache for my queries that I have set cacheable = true. If I switch the provider to the NHibernate.Cache.HashtableCacheProvider and test it works as expected.

here are the relevant config sections I am using

<configuration>
  <configSections>
  <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler,NHibernate" />
  <section name="memcache" type="NHibernate.Caches.MemCache.MemCacheSectionHandler,NHibernate.Caches.MemCache" />
  </configSections>
  <memcache>
    <memcached host="192.168.215.60" port="11211" />
  </memcache>

  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.provider">
        NHibernate.Connection.DriverConnectionProvider
      </property>
      <property name="dialect">
        MT.Core.Persistence.Dialect, MT.Core
      </property>
      <property name="connection.driver_class">
        NHibernate.Driver.SqlClientDriver
      </property>
      <property name="connection.connection_string">
        Server=192.168.1.1;Initial Catalog=Test;User ID=TestUser;Password=fakepassword;
      </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">NHibernate.Caches.MemCache.MemCacheProvider,NHibernate.Caches.MemCache</property>
      <!--<property name="cache.provider_class">NHibernate.Cache.HashtableCacheProvider</property>-->
      <property name="cache.use_second_level_cache">true</property>
      <property name="cache.use_query_cache">true</property>
    </session-factory>

  </hibernate-configuration>
</configuration>
A: 

I think that the expiration property should set for the memcache provider on the session factory level and not on the provider configuration like others (SysCache)

<property name="expiration">300</property>
Matthieu
there is a property under session factory for cache.default_expiration but adding this does not get the cache working. I can still see two queries to the database in a test where I should see one.
CountCet
have you try expiration because I use memcache and it's working for me.
Matthieu
yes inside <session-factory> I added that exact property and it throws and exception. I am on Nhibernate 2.1.2
CountCet
more detail: The 'name' attribute is invalid - The value 'expiration' is invalid according to its datatype 'String' - The Enumeration constraint failed
CountCet
Log4net actually shows me now that it fails to connectFailed to get SockIO obj for: 192.168.215.60:11211 -- new socket is not connectedNot sure why I can telnet into the server, yet nhibernate does not open on that port
CountCet
+1  A: 

The problem ended up being due to a connectivity problem. I used log4net to log any errors to the console and to the application log. It was then I finally saw the errors regarding connecting to the memcached server. Once the code was promoted to a server in the same location the errors were gone. I should have learned to use log4net ages ago.

CountCet