CompositeCacheManager
A composite cache manager is used to manage multiple cache managers containing multiple caches. Composite cache manager implementation iterates over a given collection of CacheManager instances. Allows NoOpCacheManager to be automatically added to the list for handling the cache declarations without a backing store. To mix local and distributed caches, use the CompositeCacheManager, demonstrated in Listing 10-23.
Listing 10-23. Spring configuration of CompositeCacheManager
[xml]
[/xml]
Spring’s Support – Cache Storage Libraries
Spring Framework supports two cache storage libraries namely EhCache and ConcurrentMap. Spring has given appropriate cache managers and required factory implementations for these. In this section we will discuss in detail the integration between your application and these cache storage libraries in detail along with its features as well as pros and cons of using these cache libraries with your Spring application.
JDK ConcurrentMap based Cache
The JDK-based Cache implementation resides under org.springframework.cache.concurrent package in the Spring Framework. It allows to use ConcurrentHashMap as a backing Cache store. In Listing 10-24 below, SimpleCacheManager class is used to create the CacheManager. Two caches are created, one being default and other one named “customers”.
Listing 10-24. Spring configuration of CompositeCacheManager
[xml]
[/xml]
When to choose ConcurrentMap based cache in your Spring application can be influenced by looking at the various advantages and disadvantages of this as summarized below.
Advantages of Using ConcurrentMap
Choosing ConcurrentMap offers the following advantages:
- Simpler and easy to implement
- Works well for small data which are more or less static and or which rarely change
Disadvantages of Using ConcurrentMap
Choosing ConcurrentMap offers the following disadvantages:
- No built in way to share data across multiple JVM’s. Lacks distributable capability
- Difficult to figure out the usage of heap memory being used up by the cache
- No capability of storing data outside Java heap memory
- No built in eviction algorithms present
- No built in statistics gathering capabilities
Page Visitors: 13097

Tomcy John

Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023
Every weekend i used to go to see this web site, for the reason that i want enjoyment, since
this this web page conations actually pleasant funny data too.
I don’t know whether i should take your comment as positive or negative.. :). If it is positive, thank you. If it is negative, please let me know what i can improve on to make it positive.. 🙂
Regards
Tomcy John
Hi,
Is there a PDF version of this article, or at least a Web version somewhere else? This Website is really bad (full of ads) and the code samples are incomplete.
Thanks,
Lukasz
Hi Lukasz,
I plan to have a ad free version of the entire book. For that, though, i plan to distribute with a small charge. By end of October I plan to release using “Gumroad”. If you are still interested, with a small fee you can download and enjoy an ad free version of the book.
Regards
Tomcy John