Hazelcast Map TTL无法使用spring缓存抽象

时间:2013-10-09 14:29:23

标签: java spring caching distributed-caching hazelcast

我试图让Hazelcast 3.0.2使用Spring抽象,但似乎TTL功能无效。

我已按以下方式配置弹簧上下文

<cache:annotation-driven cache-manager="cacheManager" mode="proxy" proxy-target-class="true" />
<bean id="cacheManager" class="com.hazelcast.spring.cache.HazelcastCacheManager">
    <constructor-arg ref="hzInstance" />
</bean>
<hz:hazelcast id="hzInstance">
    <hz:config>
        <hz:group name="instance" password="password" />
        <hz:properties>
            <hz:property name="hazelcast.merge.first.run.delay.seconds">5</hz:property>
            <hz:property name="hazelcast.merge.next.run.delay.seconds">5</hz:property>
            <hz:property name="hazelcast.logging.type">slf4j</hz:property>
            <hz:property name="hazelcast.jmx">true</hz:property>
            <hz:property name="hazelcast.jmx.detailed">true</hz:property>
        </hz:properties>
        <hz:network port="8995" port-auto-increment="true">
            <hz:join>
                <hz:tcp-ip enabled="true">
                    <hz:interface>10.0.5.5</hz:interface>
                    <hz:interface>10.0.5.7</hz:interface>
                </hz:tcp-ip>                           
            </hz:join>
        </hz:network>
        <hz:map name="somecache"
                backup-count="1"
                max-size="0"
                eviction-percentage="30"
                read-backup-data="false"
                time-to-live-seconds="120"
                eviction-policy="NONE"
                merge-policy="hz.ADD_NEW_ENTRY" />
    </hz:config>
</hz:hazelcast>

然后,我创建了一个简单的测试类,具有以下方法

@Cacheable("somecache")
public boolean insertDataIntoCache(String data) {
    logger.info("Inserting data = '{}' into cache",data);
    return true;
}

我还制作了一些方法来打印Hazelcast发现的每张地图中的一些信息以及内部的内容。插入数据和缓存似乎工作正常,但即使我设置了120秒的TTL,条目也永远不会过期。

当我从缓存中写入数据时,它向我显示有一个名为“somecache”的地图,并且该地图的TTL为120秒,但是当我遍历这些条目时,它会找到我使用expirationTime插入的所有数据。我不是应该是hazelcast的行为(也许地图ttl优先于条目ttl),但无论如何它都不会过期。

有人知道3.0.2和弹簧缓存有什么问题吗?我还应该提一下,我在运行较旧版本的Hazelcast的同一应用服务器中有其他应用程序,但是它们有自己独立的配置,我的测试应用程序似乎保持自身并且不会与任何内容发生冲突。

赞赏任何意见。

编辑1:

如果我降级到使用HZ 2.6.3似乎有效,所以看起来在关于TTL的hazelcast 3中有一个错误

1 个答案:

答案 0 :(得分:3)

我偶然发现了同样的事情,似乎它已在一个月前修复过:https://github.com/hazelcast/hazelcast/commit/602ce5835a7cc5e495b8e75aa3d4192db34d8b1a#diff-d20dd943d2216ab106807892ead44871

当您使用Hazelcast Spring集成时,基本上会覆盖TTL。