title: Which Java collection should I use to implement a thread-safe cache?
body: <p>I'm looking to implement a simple cache without doing too much work (naturally).  It seems to me that one of the standard Java collections ought to suffice, with a little extra work.  Specifically, I'm storing responses from a server, and the keys can either be the request URL string or a hash code generated from the URL.</p>
  
  <p>I originally thought I'd be able to use a <code>WeakHashMap</code>, but it looks like that method forces me to manage which objects I want to keep around, and any objects I don't manage with strong references are immediately swept away.  Should I try out a <code>ConcurrentHashMap</code> of <code>SoftReference</code> values instead?  Or will those be cleaned up pretty aggressively too?</p>
  
  <p>I'm now looking at the <code>LinkedHashMap</code> class.  With some modifications it looks promising for an MRU cache.  Any other suggestions?</p>
  
  <p>Whichever collection I use, should I attempt to manually prune the LRU values, or can I trust the VM to bias against reclaiming recently accessed objects?</p>
  
  <p>FYI, I'm developing on Android so I'd prefer not to import any third-party libraries.  I'm dealing with a very small heap (16 to 24 MB) so the VM is probably pretty eager to reclaim resources.  I assume the GC will be aggressive.</p>