我一直在这里待了好几天。我已经配置了我的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>
会话工厂下有一个属性,用于cache.default_expiration,但添加此操作不会使缓存工作。在测试中,我仍然可以看到数据库的两个查询,我应该看到一个。 – CountCet 2010-01-07 17:32:03
你有没有尝试过期,因为我使用了memcache,它对我有用。 – MatthieuGD 2010-01-07 17:44:01
是在里面我添加了那个确切的属性,它抛出异常。我在Nhibernate 2.1.2 –
CountCet
2010-01-07 18:10:29