14

I'm trying to decide which of these two to use in my project: guava cache or ehcache. Looking for a lightweight service level caching solution. I've searched for some benchmarks, but couldn't find any.

If you've have a benchmark handy, please post it here.

Cheers.

Raul
  • 1,899
  • 2
  • 20
  • 32

1 Answers1

22

Benchmarking is a slippery business. It's hard to get it right and easy to fake. Unless your app will squeeze out every CPU cycle out of metal, you shouldn't be worried about performance: both Ehcache and guava cache are good enough for an average project.

Things you should be paying attention are API and features. For example, Guava cache can not be used as 2nd level Hibernate cache (that is, at least out of the box). OTOH Ehcache has grown a little bit fat in terms of API and feature creeping but these things are subjective.

Coming back on topic, Guava cache was originally pulled from a separate project, concurrentlinkedhashmap which, I believe, is no longer supported as such is just a one-man project and lost a bit of momentum (see the comment below this post). Nevertheless, old project page still has some benchmarks proving ConcurrentHashMap (now guava Cache) performance being close to ConcurrentLinkedHashMap. I hope it didn't deteriorate.

mindas
  • 26,463
  • 15
  • 97
  • 154
  • 11
    I still support CLHM, but its a one-man project. CLHM has a better algorithmic foundation and heavy users, but Guava is better for the common case due to more features and a dedicated team. Performance is slightly worse post v1 due to supporting strict LRU to appease unit tests for migrations (complaints that non-strict was a bug), whereas Guava's Cache is non-strict but trusted due to being Google branded. Last time I benchmarked CLHM was barely faster than Guava, despite this penalty. All are excellent choices. – Ben Manes Dec 19 '12 at 04:32
  • Guava is already present in my project, so I'll just use it's caching support. If the project's necessities will grow, I'll then consider other libs. – Raul Aug 12 '13 at 17:05
  • 3
    For future reference, see these [JMH benchmarks](https://github.com/ben-manes/caffeine/wiki/Benchmarks) for a comparison. – Ben Manes May 25 '15 at 05:41