Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

guava cache vs ehcache benchmark [closed]

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.

like image 445
Raul Avatar asked Dec 18 '12 17:12

Raul


People also ask

Is Guava cache thread safe?

Cache entries are manually added using get(Object, Callable) or put(Object, Object) , and are stored in the cache until either evicted or manually invalidated. Implementations of this interface are expected to be thread-safe, and can be safely accessed by multiple concurrent threads.

What is a Guava cache?

The Guava Cache is an incremental cache, in the sense that when you request an object from the cache, it checks to see if it already has the corresponding value for the supplied key. If it does, it simply returns it (assuming it hasn't expired).

Is Guava in memory cache?

Guava provides a very powerful memory based caching mechanism by an interface LoadingCache<K,V>. Values are automatically loaded in the cache and it provides many utility methods useful for caching needs.

How do I refresh Guava cache?

For automatic cache refresh we can do as follows: cache = CacheBuilder. newBuilder() . refreshAfterWrite(15, TimeUnit.


1 Answers

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.

like image 92
mindas Avatar answered Oct 09 '22 22:10

mindas