【问题标题】:Add Time to live to property to my cache将居住时间添加到我的缓存中
【发布时间】:2012-12-19 20:41:37
【问题描述】:
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
    xmlns:gfe="http://www.springframework.org/schema/gemfire"
    xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

    <util:properties id="gemfire-props">
        <prop key="log-level">warning</prop>
    </util:properties>

    <gfe:cache properties-ref="gemfire-props" />

    <gfe:local-region id="LocalRegion1">
        <gfe:cache-listener>
            <bean
                class="com.mycompany.util.LoggingCacheListener" />
        </gfe:cache-listener>
    </gfe:local-region>

</beans>

我们如何为 LocalRegion1 或上面定义的缓存添加生存时间属性?我想每 24 小时完全刷新一次缓存并从服务器获取新数据。我使用本地缓存,它从服务器获取一些数据并在本地存储。

【问题讨论】:

    标签: java gemfire cache-expiration spring-data-gemfire


    【解决方案1】:

    您可以通过添加 region-ttl 节点来设置区域的生存时间,如下所述:

    <gfe:local-region id="LocalRegion1">
        <gfe:region-ttl timeout="${local.region1.ttl}" action="DESTROY"/>
        <gfe:cache-listener>
            <bean
                class="com.mycompany.util.LoggingCacheListener" />
        </gfe:cache-listener>
    </gfe:local-region>    
    

    在此示例中,您可以使用名为 local.region1.ttl 的属性设置生存时间(以秒为单位)。当然,您可以随时重命名该属性或使用文字代替(60 秒):

    <gfe:region-ttl timeout="60" action="DESTROY"/>
    

    请注意,每次更新/向区域添加条目时都会重置计时器。

    【讨论】:

      猜你喜欢
      • 2018-11-07
      • 2020-07-10
      • 2017-05-12
      • 1970-01-01
      • 1970-01-01
      • 2016-04-16
      • 1970-01-01
      • 2016-01-19
      • 1970-01-01
      相关资源
      最近更新 更多