本文介绍了NHibernate.Caches.MemCache web.config用于缓存过期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm migrating to Nhibernate 2.0 GA but have some trouble with setting cache expirations in memcached provider.

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

I see in the NHibernate.Caches.MemCache sources that there is a property for expiration and a default value for 300 seconds.

还有一些用于缓存区域的属性,但是config节处理程序似乎并未映射它们.

There are also properties for cache regions but the config section handler does not seem to map them.

还有其他设置缓存过期时间的方法吗?

Is there some other way cache expiration times are set that is not provider specific --

这是功能性的Web配置部分(显然没有过期设置).

Here is functional web config section (without an expiration settings obviously).

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

推荐答案

使用有效期.

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

之后,在运行带有日志记录的应用程序时,您会看到:

After that, when you run app with logging you can see:

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

这篇关于NHibernate.Caches.MemCache web.config用于缓存过期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 23:27