13

What is the difference between net.sf.ehcache and org.ehcache?

The current version of net.sf.ehcache is 2.10.5 whereas same for org.ehcache is 3.5.2.

Spring uses net.sf.ehcache's CacheManager, and org.ehcache's CacheManager isn't compatible for same.

Is there any specific reason for this? Please explain.

H S Raju
  • 380
  • 3
  • 12
  • I found an appropriate answer here : [difference-relationship-between-ehcache-v2-and-ehcache-v3](https://stackoverflow.com/questions/47163873/difference-relationship-between-ehcache-v2-and-ehcache-v3) – H S Raju Aug 10 '18 at 05:17
  • Possible duplicate of [Difference / Relationship between EhCache v2 and EhCache v3](https://stackoverflow.com/questions/47163873/difference-relationship-between-ehcache-v2-and-ehcache-v3) – eis Mar 05 '19 at 12:14

2 Answers2

5

As you can verify on the page http://www.ehcache.org/downloads/, Ehcache 3 is using the package prefix org.ehcache and Ehcache 2 is using the package prefix net.sf.ehcache. That's it.

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
  • 2
    Package difference is evident. One more difference is that Ehcache2 was on SVN repo whereas Ehcache3 is on GIT repo. But is there no other difference at all? – H S Raju Aug 07 '18 at 04:40
3

There are different in many levels. With ehcache 3.x, Element is not there anymore. One should directly put the key and value in the Cache therefore you can provide types when you create cache:

      Cache<Long, String> myCache = cacheManager.getCache("myCache", Long.class, String.class);

And consequently when retrieving the value, you avoid the hassle of getObjectValue instead you just treat Cache like a ConcurrentMap. So you won't get NullPointerException if the key doesn't exist, so you won't need check for cache.get(cacheKey) != null

cache.get(cacheKey);

The way to instantiate CacheManager has also changed. You won't getInstance so it is not singleton anymore. Instead you get a builder, which is way nicer, especially that you can provide it with configuration parameters inline:

        CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
            .withCache("preConfigured",
                       CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
                                                      ResourcePoolsBuilder.heap(100))
                       .build())
                        .build(true);
Shilan
  • 813
  • 1
  • 11
  • 17