Simple is beautiful: Guava LoadingCache
Cache is king . Database lookups can be expensive and RAM prices have been falling for years to the point that developers don't care anymore (ops do, btw). So what if you could use those gigabytes of RAM for caching expensive queries or frequently used data? If you are a Java developer chances are that you came across Ehcache , Spring cache, or perhaps rolled your own. Disclaimer: not the Guava cited in this post Grails bundles Ehcache because it can be used by Hibernate and also has a plugin which allows to cache methods just by annotating them. Unfortunately Ehcache has some quirks and with the stock configuration it will also not allow parallel deployment (I documented a fix here on this blog). An alternative cache implementation that I recently had a chance to use is the Guava LoadingCache . The implementation is so elegant that it will make you want to use it everywhere! Basically you build a cache, configure TTL and size (optional) and supply a lo...