// If putIfAbsent and entry already present, skip early
if (!isCreated && isPutIfAbsent)
return prev;
V ret;
Duration ttl = isCreated
? Expiration.getExpiry(expiryPolicy, Expiration.Operation.CREATION)
: Expiration.getExpiry(expiryPolicy, Expiration.Operation.UPDATE);
try {
if (ttl == null || ttl.isEternal()) {
ret = isPutIfAbsent
? cache.putIfAbsent(key, value)
: cache.put(key, value);
} else if (ttl.equals(Duration.ZERO)) {
// TODO: Can this be avoided?
// Special case for ZERO because the Infinispan remove()
// implementation returns true if entry was expired in the removal
// (since it was previously stored). JSR-107 TCK expects that if
// ZERO is passed, the entry is not stored and removal returns false.
// So, if entry is created, do not store it in the cache.
// If the entry is modified, explicitly remove it.
if (!isCreated)
ret = cache.remove(key);
else
ret = null;
} else {
long duration = ttl.getDurationAmount();
TimeUnit timeUnit = ttl.getTimeUnit();
ret = isPutIfAbsent
? cache.putIfAbsent(key, value, duration, timeUnit)
: cache.put(key, value, duration, timeUnit);
}