You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner. It is now read-only.
When put item more then map capacity, we should reduce the top item valuesSize first.
This is what I do.
@OverRide
public V put(K key, V value) {
Objects.requireNonNull(key, "key == null");
Objects.requireNonNull(value, "value == null");
V previous;
synchronized (this){
if(map.size() + 1 > capacity){
Map.Entry<K, V> toRemove = map.entrySet().iterator().next();
memorySize -= getValueSize(toRemove.getValue());
}
previous = map.put(key, value);
memorySize += getValueSize(value);
if(previous != null){
memorySize -= getValueSize(previous);
}
trimToSize(maxMemorySize);
}
return previous;
}