mirror of
https://github.com/correl/mage.git
synced 2024-11-29 03:00:12 +00:00
* Performance: improved memory usage for images (now xmage will not eat all available memory on 2GB+ settings, see #6375);
This commit is contained in:
parent
233e12873e
commit
cb2ae0295f
2 changed files with 18 additions and 7 deletions
|
@ -1,23 +1,28 @@
|
||||||
package mage.client.util;
|
package mage.client.util;
|
||||||
|
|
||||||
import static com.google.common.cache.CacheBuilder.newBuilder;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.ForwardingLoadingCache;
|
import com.google.common.cache.ForwardingLoadingCache;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static com.google.common.cache.CacheBuilder.newBuilder;
|
||||||
|
|
||||||
public class SoftValuesLoadingCache<K, V> extends ForwardingLoadingCache<K, Optional<V>> {
|
public class SoftValuesLoadingCache<K, V> extends ForwardingLoadingCache<K, Optional<V>> {
|
||||||
|
|
||||||
private final LoadingCache<K, Optional<V>> cache;
|
private final LoadingCache<K, Optional<V>> cache;
|
||||||
private static final Logger logger = Logger.getLogger(SoftValuesLoadingCache.class);
|
private static final Logger logger = Logger.getLogger(SoftValuesLoadingCache.class);
|
||||||
|
|
||||||
public SoftValuesLoadingCache(CacheLoader<K, Optional<V>> loader) {
|
public SoftValuesLoadingCache(CacheLoader<K, Optional<V>> loader) {
|
||||||
cache = newBuilder().softValues().build(loader);
|
cache = newBuilder()
|
||||||
|
.maximumSize(3000)
|
||||||
|
.expireAfterAccess(60, TimeUnit.MINUTES)
|
||||||
|
.softValues()
|
||||||
|
.build(loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class CardPanelRenderImpl extends CardPanel {
|
public class CardPanelRenderImpl extends CardPanel {
|
||||||
|
|
||||||
|
@ -219,7 +220,12 @@ public class CardPanelRenderImpl extends CardPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map of generated images
|
// Map of generated images
|
||||||
private final static Cache<ImageKey, BufferedImage> IMAGE_CACHE = CacheBuilder.newBuilder().softValues().build();
|
private final static Cache<ImageKey, BufferedImage> IMAGE_CACHE = CacheBuilder
|
||||||
|
.newBuilder()
|
||||||
|
.maximumSize(3000)
|
||||||
|
.expireAfterAccess(60, TimeUnit.MINUTES)
|
||||||
|
.softValues()
|
||||||
|
.build();
|
||||||
|
|
||||||
// The art image for the card, loaded in from the disk
|
// The art image for the card, loaded in from the disk
|
||||||
private BufferedImage artImage;
|
private BufferedImage artImage;
|
||||||
|
|
Loading…
Reference in a new issue