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.