diff --git a/core/java/src/net/i2p/data/PublicKey.java b/core/java/src/net/i2p/data/PublicKey.java index a52f6a50b9..556ca95e66 100644 --- a/core/java/src/net/i2p/data/PublicKey.java +++ b/core/java/src/net/i2p/data/PublicKey.java @@ -21,7 +21,7 @@ import java.io.IOException; */ public class PublicKey extends SimpleDataStructure { public final static int KEYSIZE_BYTES = 256; - private static final int CACHE_SIZE = 256; + private static final int CACHE_SIZE = 1024; private static final SDSCache _cache = new SDSCache(PublicKey.class, KEYSIZE_BYTES, CACHE_SIZE); diff --git a/core/java/src/net/i2p/data/SDSCache.java b/core/java/src/net/i2p/data/SDSCache.java index 2108093332..b0161c6ffd 100644 --- a/core/java/src/net/i2p/data/SDSCache.java +++ b/core/java/src/net/i2p/data/SDSCache.java @@ -3,6 +3,7 @@ package net.i2p.data; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; +import java.lang.ref.WeakReference; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.LinkedHashMap; @@ -56,7 +57,7 @@ public class SDSCache { } /** the LRU cache */ - private final Map _cache; + private final Map> _cache; /** the byte array length for the class we are caching */ private final int _datalen; /** the constructor for the class we are caching */ @@ -111,7 +112,11 @@ public class SDSCache { V rv; Integer key = hashCodeOf(data); synchronized(_cache) { - rv = _cache.get(key); + WeakReference ref = _cache.get(key); + if (ref != null) + rv = ref.get(); + else + rv = null; if (rv != null && DataHelper.eq(data, rv.getData())) { // found it, we don't need the data passed in any more SimpleByteCache.release(data); @@ -127,7 +132,7 @@ public class SDSCache { } catch (InvocationTargetException e) { throw new RuntimeException("SDSCache error", e); } - _cache.put(key, rv); + _cache.put(key, new WeakReference(rv)); found = 0; } } diff --git a/core/java/src/net/i2p/data/SigningPublicKey.java b/core/java/src/net/i2p/data/SigningPublicKey.java index e2e0cf367e..2145e95262 100644 --- a/core/java/src/net/i2p/data/SigningPublicKey.java +++ b/core/java/src/net/i2p/data/SigningPublicKey.java @@ -22,7 +22,7 @@ import java.io.IOException; */ public class SigningPublicKey extends SimpleDataStructure { public final static int KEYSIZE_BYTES = 128; - private static final int CACHE_SIZE = 256; + private static final int CACHE_SIZE = 1024; private static final SDSCache _cache = new SDSCache(SigningPublicKey.class, KEYSIZE_BYTES, CACHE_SIZE);