Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring ehcache vs Memcached?

I have worked on spring cahing using ehcache . To me it is like same with different set of API exposed and their implementation.

What's the difference in terms of features provided between them apart from API/implementation ?

Update:- I have already seen Hibernate EHCache vs MemCache but that question is mainly from hibernate perspective but my question is in general for any caching service . Answer to that question also states there is not much difference in terms of features

like image 309
scott miles Avatar asked Feb 24 '17 14:02

scott miles


1 Answers

Aside from the API differences you noted, the major difference here is going to be that memcached lives in a different process while Ehcache is internal to the JVM - unless configured to store on disk or in a cluster.

This mainly means that with Memcached you always need a serialized version of your objects and you always interact with a different process, remote or not.

Ehcache, and other JVM based caching solutions, start with a on-heap based cache initially which allows lookups to be simply about handling references to your Java objects.

Of course this means that the objects keep living in the Java heap, increasing memory pressure. In the case of Ehcache 3.x you have the option to move to offheap memory and more, allowing to grow the cache without impacting JVM heap.

At this point, the benefit of Memcached may be that you want non Java clients to access it.

And the final decision really is in your hands. Caches are consuming memory to provide reduced latency. What works for you may be different than what works for others. You have to measure and decide.

like image 169
Louis Jacomet Avatar answered Nov 09 '22 16:11

Louis Jacomet