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.
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.
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).
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.
For automatic cache refresh we can do as follows: cache = CacheBuilder. newBuilder() . refreshAfterWrite(15, TimeUnit.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With