将属性的时间添加到我的缓存中

时间:2012-12-19 20:41:38

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

<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小时彻底刷新一次缓存并从服务器获取新数据。我使用本地缓存,从服务器获取一些数据并在本地存储。

1 个答案:

答案 0 :(得分: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"/>

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