Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 956
H S Raju Avatar asked Jul 31 '18 10:07

H S Raju


People also ask

What is Net SF Ehcache?

Ehcache is an open source, standards-based cache used to boost performance, offload the database and simplify scalability. Ehcache is robust, proven and full-featured and this has made it the most widely-used Java-based cache.

What is Ehcache library used for?

Ehcache is an open source, standards-based cache that boosts performance, offloads your database, and simplifies scalability. It's the most widely-used Java-based cache because it's robust, proven, full-featured, and integrates with other popular libraries and frameworks.

Is Ehcache in memory cache?

In this article, we will introduce Ehcache, a widely used, open-source Java-based cache. It features memory and disk stores, listeners, cache loaders, RESTful and SOAP APIs and other very useful features.

What is Ehcache in spring boot?

EhCache is a widely used, pure Java cache that can be easily integrated with most popular Java frameworks, such as Spring and Hibernate. It is often considered to be the most convenient choice for Java applications since it can be integrated into projects easily.


2 Answers

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.

like image 195
Ortomala Lokni Avatar answered Oct 25 '22 08:10

Ortomala Lokni


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);
like image 42
Shilan Avatar answered Oct 25 '22 09:10

Shilan