Changeset fdc3af9


Ignore:
Timestamp:
Sep 6, 2011 12:13:33 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
d9b37ac
Parents:
5030a86
Message:
  • SDSCache: Use weak refs; increase size for pub keys
Location:
core/java/src/net/i2p/data
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/PublicKey.java

    r5030a86 rfdc3af9  
    2222public class PublicKey extends SimpleDataStructure {
    2323    public final static int KEYSIZE_BYTES = 256;
    24     private static final int CACHE_SIZE = 256;
     24    private static final int CACHE_SIZE = 1024;
    2525
    2626    private static final SDSCache<PublicKey> _cache = new SDSCache(PublicKey.class, KEYSIZE_BYTES, CACHE_SIZE);
  • core/java/src/net/i2p/data/SDSCache.java

    r5030a86 rfdc3af9  
    44import java.io.IOException;
    55import java.io.InputStream;
     6import java.lang.ref.WeakReference;
    67import java.lang.reflect.Constructor;
    78import java.lang.reflect.InvocationTargetException;
     
    5758
    5859    /** the LRU cache */
    59     private final Map<Integer, V> _cache;
     60    private final Map<Integer, WeakReference<V>> _cache;
    6061    /** the byte array length for the class we are caching */
    6162    private final int _datalen;
     
    112113        Integer key = hashCodeOf(data);
    113114        synchronized(_cache) {
    114             rv = _cache.get(key);
     115            WeakReference<V> ref = _cache.get(key);
     116            if (ref != null)
     117                rv = ref.get();
     118            else
     119                rv = null;
    115120            if (rv != null && DataHelper.eq(data, rv.getData())) {
    116121                // found it, we don't need the data passed in any more
     
    128133                    throw new RuntimeException("SDSCache error", e);
    129134                }
    130                 _cache.put(key, rv);
     135                _cache.put(key, new WeakReference(rv));
    131136               found = 0;
    132137            }
  • core/java/src/net/i2p/data/SigningPublicKey.java

    r5030a86 rfdc3af9  
    2323public class SigningPublicKey extends SimpleDataStructure {
    2424    public final static int KEYSIZE_BYTES = 128;
    25     private static final int CACHE_SIZE = 256;
     25    private static final int CACHE_SIZE = 1024;
    2626
    2727    private static final SDSCache<SigningPublicKey> _cache = new SDSCache(SigningPublicKey.class, KEYSIZE_BYTES, CACHE_SIZE);
Note: See TracChangeset for help on using the changeset viewer.