Ehcache Alternative:
Why Redisson is the Best Ehcache Replacement
Ehcache is an open-source distributed cache written in the Java programming language that calls itself "the most widely-used Java-based cache." The features of Ehcache include a lightweight footprint, memory and disk stores, REST and SOAP APIs, and more.
While Ehcache has a lot to recommend it, it's not the right choice for every caching use case. In particular, Ehcache alternatives such as Redis may be better suited for your own situation.
Redis is an in-memory data structure store frequently used to implement caches and non-relational key-value databases. The advantages of Redis only increase when you install a third-party Redis Java client such as Redisson.
If you're looking for an Ehcache replacement, Redis and Redisson might be the right solution for you. Below, we'll discuss why Redis is the best Ehcache alternative.
Ehcache vs. Redis (with Redisson)
Although Ehcache and Redis are frequently compared, there are a few important distinctions to make between the two offerings.
For example, Ehcache is implemented in Java, which means that it can run on any operating system with a Java virtual machine. Redis is written in C, but includes support for more than two dozen programming languages, including Java, C/C++, Python, Ruby, and Haskell. Linux and macOS are the most common operating systems used with Redis; there is no official support for Redis on Windows.
The personal finance software tool Personal Capital recently switched from Ehcache to Redis for their caching and asynchronous event-based processing needs. According to software engineer Ankit Kumar, Redis offers several benefits over Ehcache for Personal Capital:
- Redis is easily horizontally scalable, whereas Ehcache is not.
- The Redis cache can run on dedicated servers run by cloud providers such as AWS ElastiCache and Azure Cache for Redis.
- Redis allows for zero-downtime deployments, whereas Ehcache does not.
Given these advantages, choosing Redis over Ehcache was a "no-brainer" for Personal Capital. In the next section, we'll discuss a few more reasons why you might choose Redis+Redisson over Ehcache.
Why Redisson is the Best Ehcache Alternative
1. Distributed objects, collections, and locks and synchronizers
In the Ehcache vs. Redis matchup, Redis+Redisson is the clear winner when it comes to Java distributed objects and collections.
Both Redis and Ehcache include an implementation of distributed Maps in Java. However, the comparison ends there. Redis+Redisson supports many Java distributed collections that Ehcache does not, such as:
- Multimap
- Set
- List
- Queue
- Deque
- SortedSet
- ScoredSortedSet
- PriorityQueue
- PriorityDeque
- DelayedQueue
- TransferQueue
- RingBuffer
- Stream
Redis+Redisson only increases its lead when it comes to Java distributed locks and synchronizers. Both Ehcache and Redis+Redisson support Lock and ReadWriteLock objects, but Redis+Redisson implements an additional four types of locks and synchronizers:
- Semaphore
- CountDownLatch
- FairLock
- MultiLock
Finally, Redis supports a variety of other Java distributed objects that Ehcache does not, including:
- ObjectHolder
- AtomicLong
- Publish/Subscribe
- AtomicDouble
- Geospatial
- BitSet
- BloomFilter
- BinaryStream
- HyperLogLog
With so many implementations of Java distributed objects, locks, and collections, Redis+Redisson has a much smoother learning curve for developers.
2. API architecture
Asynchronous, reactive, and RxJava2 are popular paradigms for parallel and asynchronous programming in Java. However, both Ehcache and base Redis don't include support for any of the three.
The good news is that Redisson adds built-in support for all three programming models - asynchronous, reactive, and RxJava2. Thanks to Redisson's support for multiple API architectures, you can significantly improve performance by parallelizing your computations.
3. Custom data serialization
When saving to and loading from a Redis database, objects should be serialized and deserialized. Redisson lends a helping hand by including many different data serialization codecs: JDK, JSON, Avro, Smile, CBOR, MsgPack, Kryo, FST, LZ4 compression, and Snappy compression.
However, data serialization options in Ehcache are sparse by comparison. Ehcache only includes a built-in JDK codec, which means that you'll have to implement other options yourself.
4. Fully managed services
Fully managed cloud services are a lifesaver for developers who don't want to spend too much time and effort managing their deployments. Redis+Redisson is available as a fully managed service out of the box on multiple public cloud platforms, including:
- Amazon ElastiCache for Redis
- Azure Cache for Redis
- IBM Cloud Databases for Redis
- ObjectRocket for Redis
As of writing, however, the same is not true for Ehcache. Developers who plan to deploy Ehcache in the cloud will need to manage it themselves, which adds to the work for your IT department.