我一直在這裏待了好幾天。我已經配置了我的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