2010-01-07 90 views
2

我一直在这里待了好几天。我已经配置了我的web/app配置,使用Memcached服务器和NHContrib提供者的二级缓存。我在测试中没有遇到任何异常,我发现它没有使用缓存来处理我设置了cacheable = true的查询。 如果我将提供者切换到NHibernate.Cache.HashtableCacheProvider并测试它的工作方式如预期。NHibernate的Memcached Provider不能正常工作

这里是我使用

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

回答

0

相关配置部分我认为到期属性应为在会话工厂级别的内存缓存提供商设置的,而不是像其他人(SysCache)

提供商配置
<property name="expiration">300</property> 
+0

会话工厂下有一个属性,用于cache.default_expiration,但添加此操作不会使缓存工作。在测试中,我仍然可以看到数据库的两个查询,我应该看到一个。 – CountCet 2010-01-07 17:32:03

+0

你有没有尝试过期,因为我使用了memcache,它对我有用。 – MatthieuGD 2010-01-07 17:44:01

+0

是在里面我添加了那个确切的属性,它抛出异常。我在Nhibernate 2.1.2 – CountCet 2010-01-07 18:10:29

2

该问题最终是由于连接问题。我使用log4net将任何错误记录到控制台和应用程序日志中。那时我终于看到了连接到memcached服务器的错误。一旦将代码提升到同一位置的服务器,错误就消失了。我应该已经学会了在使用log4net之前。

2

对于memcache,属性是'default_expiration'而不是'过期'。我不确定SysCache。但是我已经将这个属性用于memcache,并且适用于我。

Initailly我也遇到了CountCet提到的同样的错误。 MemCache提供程序无法识别'expiration'属性。后来我检查了代码,发现它使用属性'default_expiration',其默认值为300秒。