2008-12-09 39 views
1

我正在遷移到Nhibernate 2.0 GA,但在memcached提供程序中設置緩存過期時遇到了一些問題。緩存過期時間的NHibernate.Caches.MemCache web.config

我在NHibernate.Caches.MemCache源中看到有一個過期屬性和默認值爲300秒。

還有緩存區域的屬性,但配置節處理程序似乎沒有映射它們。

是否有其他某種方式緩存過期時間設置不特定供應商 -

下面是功能的web配置部分(無過期設置明顯)。

<memcache> 
    <memcached host="127.0.0.1" port="11211"/> 
    <!-- or multiples --> 
</memcache> 

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
    <session-factory> 
     <property name="show_sql">true</property> 
     <property name="connection.provider" >NHibernate.Connection.DriverConnectionProvider</property> 
     <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property> 
     <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> 
       <!-- <property name="hibernate.cache.provider_class" value="NHibernate.Caches.MemCache.MemCacheProvider,NHibernate.Caches.MemCache" /> --> 
     <property name="connection.connection_string">Data Source=stage2.ripple6.com;Initial Catalog=r6stage;User Id=sa;Password=mworld7650;Application Name=Hibernate;</property> 
     <property name="connection.isolation">ReadCommitted</property> 
     <property name="cache.use_second_level_cache">true</property> 
     <property name="cache.provider_class">NHibernate.Caches.MemCache.MemCacheProvider,NHibernate.Caches.MemCache</property> 
     <property name="default_schema" >r6stage.dbo</property> 
    </session-factory> 

</hibernate-configuration> 

回答

-1

使用過期。

<property name="expiration" >YOUR_INTERVAL_IN_SECONDS</property> 

之後,當你用日誌記錄運行應用程序,你可以看到:

NHibernate.Caches.MemCache.MemCacheClient: 20:57:55,762 DEBUG MemCacheClient:0 - using expiration of YOUR_INTERVAL_IN_SECONDS seconds 
0

據我所知,緩存失效時間是提供程序特定的,因爲有些緩存提供程序不支持這一點。 此外,這意味着您沒有60的值在某些情況下表示一小時而在其他情況下表示一分鐘的情況。

1

使用default_expiration。

<property name="default_expiration" >YOUR_INTERVAL_IN_SECONDS</property> 

我在源碼中看到默認過期值設置爲300秒。但是你可以通過設置NHibernate配置文件的default_expiration屬性來覆蓋這個值。