Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache expiry is lost after an update #7236

Closed
asarigul opened this issue Jan 4, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@asarigul
Copy link

commented Jan 4, 2016

Hi all,

We are using Hazelcast as a JCache provider. As JSR 107 Javadoc states, an update should not reset expiry time for CreatedExpiryPolicy. However, if we update a cache entry, it does not expire.

Here is a test case:

@Test
public void testExpiryWithUpdate() throws InterruptedException {
    final int expiry = 2000;
    Duration duration = new Duration(TimeUnit.MILLISECONDS, expiry);
    Configuration<Integer, String> config = new MutableConfiguration<Integer, String>()
            .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(duration));

    try (Cache<Integer, String> cache = Caching.getCachingProvider().getCacheManager()
            .createCache("testCache", config)) {
        cache.put(1, "value");
        //cache.put(1, "value");
        Assert.assertNotNull(cache.get(1));
        Thread.sleep(expiry);
        Assert.assertNull(cache.get(1));
    }
}

The entries expire as expected after 2 seconds, if we did not update them (via put or replace methods), so above test succeeds.

But if we update the entry (ie: uncomment out second put call) then the entry doesn't expire and test fails. Moreover, an update does not update expire time (ie: expiry time is not extended), but cache behaves as if expiry policy is eternal. That is, the following code block prints out "...still not expired" forever (using same config as above one, with CreatedExpiry policy with 2 second expiry time).

try (Cache<Integer, String> cache = Caching.getCachingProvider().getCacheManager()
                .createCache("testCache", config)) {
    cache.put(1, "value");
    cache.put(1, "value");
    Assert.assertNotNull(cache.get(1));
    String value;
    while((value = cache.get(1)) != null) {
        System.out.println("...still not expired");
        Thread.sleep(1000);
    }
    System.out.println("Entry expired!");
}

I tried this with hazelcast versions 3.4.6, 3.5.4, and 3.6-EA3.

I can confirm that only Apache Ignite runs as expected (an update does not change/reset expiry time for CreatedExpiryPolicy). Hazelcast and Infinispan fails as I summarized above.

@serkan-ozal serkan-ozal self-assigned this Jan 4, 2016

@serkan-ozal

This comment has been minimized.

Copy link
Contributor

commented Jan 4, 2016

Hi @asarigul

Thanks for reporting the issue.

I have reproduced the issue with your test code and the problem is that expiry duration is set to -1 on update when CreatedExpityPolicy is used so this causes to keep the entry infinitely in the cache.

I will fix this issue before 3.6.

Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.