Fixed - OOM when using RLocalCachedMap.fastPut and Reference based EvictionPolicy. #1442

pull/1721/head
Nikita Koksharov 6 years ago
parent a3fec2c062
commit a71460624e

@ -221,14 +221,7 @@ public abstract class AbstractCacheMap<K, V> implements Cache<K, V> {
protected abstract void onMapFull(); protected abstract void onMapFull();
boolean isFull() { protected boolean isFull(K key) {
if (size == 0) {
return false;
}
return map.size() >= size;
}
private boolean isFull(K key) {
if (size == 0) { if (size == 0) {
return false; return false;
} }

@ -0,0 +1,27 @@
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.cache;
/**
*
* @author Nikita Koksharov
*
*/
public interface CachedValueReference {
CachedValue<?, ?> getOwner();
}

@ -24,7 +24,7 @@ import java.lang.ref.SoftReference;
* *
* @param <V> value type * @param <V> value type
*/ */
public class CachedValueSoftReference<V> extends SoftReference<V> { public class CachedValueSoftReference<V> extends SoftReference<V> implements CachedValueReference {
private final CachedValue<?, ?> owner; private final CachedValue<?, ?> owner;
@ -33,6 +33,7 @@ public class CachedValueSoftReference<V> extends SoftReference<V> {
this.owner = owner; this.owner = owner;
} }
@Override
public CachedValue<?, ?> getOwner() { public CachedValue<?, ?> getOwner() {
return owner; return owner;
} }

@ -24,7 +24,7 @@ import java.lang.ref.WeakReference;
* *
* @param <V> value type * @param <V> value type
*/ */
public class CachedValueWeakReference<V> extends WeakReference<V> { public class CachedValueWeakReference<V> extends WeakReference<V> implements CachedValueReference {
private final CachedValue<?, ?> owner; private final CachedValue<?, ?> owner;
@ -33,6 +33,7 @@ public class CachedValueWeakReference<V> extends WeakReference<V> {
this.owner = owner; this.owner = owner;
} }
@Override
public CachedValue<?, ?> getOwner() { public CachedValue<?, ?> getOwner() {
return owner; return owner;
} }

@ -45,14 +45,20 @@ public class ReferenceCacheMap<K, V> extends AbstractCacheMap<K, V> {
this.type = type; this.type = type;
} }
@Override
protected CachedValue<K, V> create(K key, V value, long ttl, long maxIdleTime) { protected CachedValue<K, V> create(K key, V value, long ttl, long maxIdleTime) {
return new ReferenceCachedValue<K, V>(key, value, ttl, maxIdleTime, queue, type); return new ReferenceCachedValue<K, V>(key, value, ttl, maxIdleTime, queue, type);
} }
@Override
protected boolean isFull(K key) {
return true;
}
@Override @Override
protected boolean removeExpiredEntries() { protected boolean removeExpiredEntries() {
while (true) { while (true) {
CachedValueSoftReference<V> value = (CachedValueSoftReference<V>) queue.poll(); CachedValueReference value = (CachedValueReference) queue.poll();
if (value == null) { if (value == null) {
break; break;
} }

Loading…
Cancel
Save