in commons-jcs3-jcache/src/main/java/org/apache/commons/jcs3/jcache/JCSCache.java [573:618]
public boolean replace(final K key, final V oldValue, final V newValue)
{
assertNotClosed();
assertNotNull(key, "key");
assertNotNull(oldValue, "oldValue");
assertNotNull(newValue, "newValue");
final boolean statisticsEnabled = config.isStatisticsEnabled();
final ICacheElement<K, V> elt = delegate.get(key);
if (elt != null)
{
V value = elt.getVal();
if (value != null && statisticsEnabled)
{
statistics.increaseHits(1);
}
if (value == null && config.isReadThrough())
{
value = doLoad(key, false, Times.now(false), false);
}
if (value != null && value.equals(oldValue))
{
put(key, newValue);
return true;
}
if (value != null)
{
final Duration expiryForAccess = expiryPolicy.getExpiryForAccess();
if (expiryForAccess != null && (!elt.getElementAttributes().getIsEternal() || !expiryForAccess.isEternal()))
{
try
{
delegate.update(updateElement(key, elt.getVal(), expiryForAccess, elt.getElementAttributes()));
}
catch (final IOException e)
{
throw new CacheException(e);
}
}
}
}
else if (statisticsEnabled)
{
statistics.increaseMisses(1);
}
return false;
}