H S Raju
H S Raju

Reputation: 410

Difference between net.sf.ehcache and org.ehcache?

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.

Upvotes: 15

Views: 9406

Answers (2)

Shilan
Shilan

Reputation: 833

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);

Upvotes: 4

Ortomala Lokni
Ortomala Lokni

Reputation: 62625

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.

Upvotes: 6

Related Questions