Source:
<code>private OnHeapValueHolder<V> putReturnHolder(final K key, final V value) throws CacheAccessException { putObserver.begin(); checkKey(key); checkValue(value); final AtomicBoolean entryActuallyAdded = new AtomicBoolean(); final long now = timeSource.getTimeMillis(); long estimatedSize = 1; long sizeOfKey = 0; if(byteSized) { sizeOfKey = getSizeOfKeyWithOffset(key); estimatedSize = getSizeOfValueWithOffset(value) + sizeOfKey + sizeOfEngine.getCHMOffset(); } final long delta = estimatedSize; final AtomicLong replacedValueSize = new AtomicLong(0l); try { OnHeapValueHolder<V> valuePut = map.compute(key, new BiFunction<K, OnHeapValueHolder<V>, OnHeapValueHolder<V>>() { @Override public OnHeapValueHolder<V> apply(K mappedKey, OnHeapValueHolder<V> mappedValue) { entryActuallyAdded.set(mappedValue == null); if (mappedValue != null && mappedValue.isExpired(now, TimeUnit.MILLISECONDS)) { mappedValue = null; } if (mappedValue == null) { return newCreateValueHolder(key, value, now); } else { if (byteSized) { replacedValueSize.set(sizeOfEngine.sizeof(mappedValue.value())); } return newUpdateValueHolder(key, mappedValue, value, now); } } }); if (entryActuallyAdded.get()) { putObserver.end(StoreOperationOutcomes.PutOutcome.PUT); <START> enforceCapacity(delta); <END> } else { putObserver.end(StoreOperationOutcomes.PutOutcome.REPLACED); if(byteSized) { long replacedDelta = delta - (sizeOfKey + replacedValueSize.get() + sizeOfEngine.getCHMOffset()); replaceByteCapacity(replacedDelta); } } return valuePut; } catch (RuntimeException re) { handleRuntimeException(re); return null; } }</code><technical_language>delta estimate a bad idea, recalculated time loop enforceCapacity() enough bytes freed store's consumption configured max bytes</technical_language>

Target:
private OnHeapValueHolder<V> putReturnHolder(final K key, final V value) throws CacheAccessException { putObserver.begin(); checkKey(key); checkValue(value); final AtomicBoolean entryActuallyAdded = new AtomicBoolean(); final long now = timeSource.getTimeMillis(); final AtomicReference<OnHeapValueHolder<V>> replacedValue = new AtomicReference<OnHeapValueHolder<V>>(null); try { OnHeapValueHolder<V> valuePut = map.compute(key, new BiFunction<K, OnHeapValueHolder<V>, OnHeapValueHolder<V>>() { @Override public OnHeapValueHolder<V> apply(K mappedKey, OnHeapValueHolder<V> mappedValue) { if (mappedValue != null && mappedValue.isExpired(now, TimeUnit.MILLISECONDS)) { mappedValue = null; } OnHeapValueHolder<V> toReturn = null; if (mappedValue == null) { toReturn = newCreateValueHolder(key, value, now); entryActuallyAdded.set(toReturn != null); } else { replacedValue.set(mappedValue); toReturn = newUpdateValueHolder(key, mappedValue, value, now); } return toReturn; } }); if (entryActuallyAdded.get()) { putObserver.end(StoreOperationOutcomes.PutOutcome.PUT); enforceCapacity(valuePut.size()); } else { putObserver.end(StoreOperationOutcomes.PutOutcome.REPLACED); long replacedDelta = valuePut == null ? 0 : valuePut.size() - (replacedValue.get() == null ? 0 : replacedValue.get().size()); replaceByteCapacity(replacedDelta); } return valuePut; } catch (RuntimeException re) { handleRuntimeException(re); return null; } }