1

While using JCache (Infinispan) on Wildfly 10.1 I stumbled against the following issue. I created a new cache (test-cache) where I used CreatedExpiryPolicy with a duration of 5 minutes.

After playing around with the cache I noticed that if I put the same key twice the cache entry will be converted to an ImmortalCacheEntry and therefore the entry will stick in the cache forever. I know I can work around this issue by using remove and put for updates but for me this sounds like a bug in Infinspan.

The JavaDoc in CreatedExpiryPolicy clearly says that updates have no affect on the current expiry duration.

CachingProvider cachingProvider = Caching.getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();

MutableConfiguration<Object, Object> config = new MutableConfiguration<>()
        .setTypes(Object.class, Object.class)
        .setStoreByValue(true)
        .setStatisticsEnabled(true)
        .setManagementEnabled(true)
        .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5)));

Cache<Object, Object> cache = cacheManager.createCache("test-cache", config);

cache.put("key", "value"); // MortalCacheEntry{key=key, value=value}}

cache.put("key", "value"); // ImmortalCacheEntry{key=key, value=value}} 

Excerpt from javax.cache.expiry.CreatedExpiryPolicy

/**
 * {@inheritDoc}
 */
@Override
public Duration getExpiryForUpdate() {
    //updating a cache entry has no affect on the current expiry duration
    return null;
}

Can anybody help my clarify if this is a bug or if I am using it wrong? If it is a bug I will create a new JIRA issue.

maroswal
  • 96
  • 6
  • What Infinispan version are you using? In the latest Infinispan 9.2.0.CR2 we have added JCache 1.1 compatibility and wondering if the same issue still persists. – Galder Zamarreño Feb 15 '18 at 16:28
  • I am using version Infinispan 8.2.4.Final that is included in Wildfly 10.1.0.Final and JCache 1.0.0. – maroswal Feb 15 '18 at 17:08
  • Confirmed; AbstractJCache, line 242: if expiration policy returns `null` or eternal, the default policy in Infinispan (eternal) is used. 9.2 contains reworked version, but the problem persists there. https://issues.jboss.org/browse/ISPN-8841 – Radim Vansa Feb 19 '18 at 11:32
  • As a workaround: have you tried an expiry policy that works the way it should? – Galder Zamarreño Feb 19 '18 at 14:15
  • Thanks for confirming the bug. Yes, as a workaround I'm using putIfAbsent method or modified expiry policy, both options are okay for my use cases. – maroswal Feb 19 '18 at 14:30

0 Answers0