开发者

Memcached Provider for NHibernate not working

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.ConfigurationSect开发者_StackOverflow中文版ionHandler,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>


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.


For memcache the property is 'default_expiration' not 'expiration'. I am not sure about SysCache. But I have used this property for memcache and it works for me.

Initailly I also faced the same error that CountCet mentioned. The attribute 'expiration' is not recognized by the MemCache provider. Later I checked the code and found that it use the property 'default_expiration' and its default value is 300 sec.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜