NHibernate.Caches.MemCache web.config for cache expiration time

℡╲_俬逩灬. 提交于 2019-12-21 06:28:19

问题


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

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

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

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>

回答1:


Use expiration.

<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



回答2:


Use default_expiration.

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

I have seen in the source that the default expiration value is set to 300 second. But you can override this value by setting default_expiration property form the NHibernate configuration file.




回答3:


As far as I understand, the cache expiry time is provider specific as some cache providers don't support this. Also, it means that you don't have the situation where a value of 60 means an hour in some cases and a minute in others.



来源:https://stackoverflow.com/questions/354419/nhibernate-caches-memcache-web-config-for-cache-expiration-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!