mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 11:32:00 -08:00
Sync old changes
This commit is contained in:
parent
caf1a98759
commit
270ec615af
4 changed files with 35 additions and 17 deletions
|
|
@ -9,10 +9,12 @@ import com.google.common.base.Function;
|
|||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.ForwardingLoadingCache;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class SoftValuesLoadingCache<K, V> extends ForwardingLoadingCache<K, Optional<V>> {
|
||||
|
||||
private final LoadingCache<K, Optional<V>> cache;
|
||||
private static final Logger logger = Logger.getLogger(SoftValuesLoadingCache.class);
|
||||
|
||||
public SoftValuesLoadingCache(CacheLoader<K, Optional<V>> loader) {
|
||||
cache = newBuilder().softValues().build(loader);
|
||||
|
|
@ -35,7 +37,14 @@ public class SoftValuesLoadingCache<K, V> extends ForwardingLoadingCache<K, Opti
|
|||
try {
|
||||
return get(key).orElse(null);
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
if (e.getCause() instanceof OutOfMemoryError) {
|
||||
logger.warn("Out of memory error: try to increase free memory in launcher options (-xmx param)");
|
||||
return null;
|
||||
} else {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue