Alexandre Thenorio
Alexandre Thenorio

Reputation: 2418

Hazelcast Map TTL not working with spring cache abstraction

I am trying to get Hazelcast 3.0.2 working with Spring abstraction however it seems the TTL functionality is not working.

I have configured my spring context in the following way

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

I then made a simple test class having the following method

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

I also made some method to print some information from every map Hazelcast finds and also the entires inside. Inserting the data and caching seems to work fine however the entry never expires even though I set a TTL of 120 seconds.

When I write the data from the cache it shows me that there is one map called "somecache" and that map has a TTL of 120 seconds but when I loop through the entries, it finds all the ones I inserted with a expirationTime of 0. I am not what is supposed to be the behaviour of hazelcast (maybe a map ttl takes precedence over an entry ttl) but in any case it will just not expire.

Is anybody aware of any issues with 3.0.2 and spring cache? I should also mention that I have other applications in the same application server running an older version of Hazelcast however they have their own separate config and my test application seems to be keeping to itself and not conflicting with anything.

Any input is appreciated.

EDIT 1:

It seems to work if I downgrade to using HZ 2.6.3 so it looks like there is a bug somewhere in hazelcast 3 regarding TTL

Upvotes: 3

Views: 4887

Answers (1)

maidokaara
maidokaara

Reputation: 33

I just stumbled on the same thing and it seems that it has been fixed about a month ago: https://github.com/hazelcast/hazelcast/commit/602ce5835a7cc5e495b8e75aa3d4192db34d8b1a#diff-d20dd943d2216ab106807892ead44871

Basically TTL was overridden when you use Hazelcast Spring integration.

Upvotes: 3

Related Questions