title: Lightweight Java Object cache API
body: <h2>Question</h2>
  
  <p>I'm looking for a Java in-memory object caching API. Any recommendations? What solutions have you used in the past?</p>
  
  <h2>Current</h2>
  
  <p>Right now, I'm just using a Map:</p>
  
  <pre><code>Map cache = new HashMap&lt;String, Object&gt;();
  cache.put("key", value);
  </code></pre>
  
  <h2>Requirements</h2>
  
  <p>I need to extend the cache to include basic features like:</p>
  
  <ul>
  <li>Max size</li>
  <li>Time to live</li>
  </ul>
  
  <p>However, I don't need more sophisticated features like:</p>
  
  <ul>
  <li>Access from multiple processes (caching server)</li>
  <li>Persistence (to disk)</li>
  </ul>
  
  <h2>Suggestions</h2>
  
  <p>In-Memory caching:</p>
  
  <ul>
  <li><a href="http://guava-libraries.googlecode.com" rel="noreferrer">Guava</a> CacheBuilder - active development. See this <a href="https://github.com/liubo404/it-ebooks/blob/master/pdf/JavaCachingwithGuava.pdf" rel="noreferrer">presentation</a>.</li>
  <li><a href="http://commons.apache.org/collections/apidocs/org/apache/commons/collections/map/LRUMap.html" rel="noreferrer">LRUMap</a> - Config via API. No TTL. Not purpose built for caching.</li>
  <li><a href="http://whirlycache.dev.java.net/" rel="noreferrer">whirlycache</a> - XML config. Mailing list. Last updated 2006.</li>
  <li><a href="http://cache4j.sourceforge.net/" rel="noreferrer">cache4j</a> - XML config. Documentation in Russian. Last updated 2006.</li>
  </ul>
  
  <p>Enterprise caching:</p>
  
  <ul>
  <li><a href="http://jakarta.apache.org/jcs" rel="noreferrer">JCS</a> - Properties config. Extensive documentation.</li>
  <li><a href="http://ehcache.sourceforge.net" rel="noreferrer">Ehcache</a> - XML config. Extensive documentation. By far the most popular according to Google hits.</li>
  </ul>