1

我正在迁移到 Nhibernate 2.0 GA,但在 memcached 提供程序中设置缓存过期时遇到了一些麻烦。

我在 NHibernate.Caches.MemCache 源中看到有一个过期属性和一个 300 秒的默认值。

缓存区域也有属性,但配置部分处理程序似乎没有映射它们。

是否有其他方式设置缓存过期时间不是特定于提供者的——

这是功能性网络配置部分(显然没有过期设置)。

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

3 回答 3

1

使用 default_expiration。

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

我在源代码中看到默认过期值设置为 300 秒。但是你可以通过在 NHibernate 配置文件中设置 default_expiration 属性来覆盖这个值。

于 2011-05-09T06:26:15.530 回答
0

据我了解,缓存到期时间是特定于提供商的,因为某些缓存提供商不支持这一点。此外,这意味着您不会遇到值 60 在某些情况下表示一小时而在其他情况下表示一分钟的情况。

于 2008-12-12T15:22:32.170 回答
-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
于 2009-01-14T19:59:50.600 回答