Ehcache based Cache
Ehcache is an excellent library which provides the community with high quality, good documentation, simple to use and wide adopted cache framework. It is one of the most popular open-source and most widely used Java-based cache frameworks available today. It scales from in-process cache to various distributed cache. It is actively developed and maintained by Terracotta.
Spring uses a proxy which intercepts call to the method of bean; consults the cache to check if method was called with same parameters before, if so will return cached result. EhCache is the actual provider of caching solution and Spring Framework handles method interception and stores the results in the cache.
There are various features in EhCache which makes it an ideal cache framework choice in your application. Some of the well known features are listed below:
- Well known in the Java community
- Simpler and easy to implement
- Can be offloaded to memory
- Can be scaled to any number of nodes
- Supports various cache eviction policies
- JMX enabled
- Have been already integrated with many frameworks like Spring, Hibernate, JRuby etc.
- Rich feature list. Some of which are (I have just highlighted the important points but haven’t gone on to explain these):
- Multiple transaction model
- Search capabilities
- Persistence storage options
- Monitoring tools availability
- Distributed cache options etc.
- Open source project managed by Terracotta along with licensed full support product
Similar to ConcurrentMap based cache; I would like to bring in both advantages as well as disadvantages of EhCache, so as to give you an idea of which one to wisely choose in your application according to your requirement.
Advantages of Using EhCache
Choosing EhCache offers the following advantages:
- Simpler and easy to implement
- Ideal for all kinds of data-sets
- Has built in eviction algorithms
- Capable of distributed data caching
- Statistics gathering capability is built-in
- Configurable built-in heap memory usage patterns. This give full control of ho much heap memory is used by the cache.
- Data can be stored outside of the Java heap memory and it can be controlled in a configurable way.
Disadvantages of Using EhCache
To be honest, I don’t see any limitation that I can put at this point in time.
Spring’s Support – Other Cache Libraries
Spring Framework’s philosophy of easy pluggability comes in lime light in this as well. Even though it has it has given its choice of integration as discussed earlier. It can be used to integrate with other caching frameworks available in the industry.
There are many caching frameworks available, but in this section we will see specifically two caching framework integration namely Oracle Coherence and SpringSource GemFire.
When configuring Coherence, it allows providing your own CacheStore implementations. CacheStore implementations intern uses some sort of resource, such as a data source. Spring provides the best way to configure all kinds of resources and manage the lifecycle of these resources in your application.
Coherence com.tangosol.net.CacheFactory class, static factory methods allows you to access all Coherence caches and services. These methods are delegate to a com.tangosol.net.ConfigurableCacheFactory interface, which can be plugged in by using theCacheFactory.setConfigurableCacheFactory method or the operational override file of coherence namely tangosol-coherence-override.xml.
The com.tangosol.coherence.spring.SpringAwareCacheFactory interface is a custom ConfigurableCacheFactory which helps in accessing caches in the Coherence configuration file and also gives the ability to reference beans configured using Spring.
The various steps involved in integration of Oracle Coherence with Spring application are summarized in the following sections.
Page Visitors: 11438