Spring Book – Chapter 10 – Caching


EhCache is a very popular open source caching framework widely used for Java based Caching. Currently it’s owned by Terracotta.org. Cache Manager, Caches and Elements are main entities of EhCache. EhCache consists of a CacheManager, which manages Caches. Caches contain Elements, which are essentially name value pairs. Caches are physically implemented either in-memory, or on disk.

Spring Framework’s CacheManager backed by an EhCache Cache is org.springframework.cache.ehcache.EhCacheCacheManager. Listing 10-18 shows a basic EhCache configuration in the Spring bean configuration file. Detailed configuration in a Spring application is covered in “Spring’s Support – Cache Storage Libraries” section.

Listing 10-18. Spring configuration of EhCache


<!– EhCache library setup –>



CacheManager implementation that lazily builds ConcurrentMapCache instances for each getCache(java.lang.String) request. Also supports a ‘static’ mode where the set of cache names is pre-defined through setCacheNames(java.util.Collection), with no dynamic creation of further cache regions at runtime. Listing 10-19 shows a basic configuration in the Spring bean configuration file. Detailed configuration in a Spring application is covered in “Spring’s Support – Cache Storage Libraries” section.

Listing 10-19. Spring configuration of ConcurrentMap



The simple cache manager works against a given collection of caches. It is useful for testing or simple caching declarations purposes. Listing 10-20 shows a basic Spring configuration file in which SimpleCacheManager is configured.

Listing 10-20. Spring configuration of SimpleCacheManager


<beancodecxspmiddle" style="margin-left:144.0pt;mso-add-space:auto">ConcurrentCacheFactoryBean" p:name="default"/>

<beancodecxspmiddle" style="margin-left:108.0pt;mso-add-space:auto; text-indent:36.0pt">ConcurrentCacheFactoryBean" p:name="customers"/>



A basic no operation CacheManager implementation suitable for disabling caching, typically used for backing cache declarations without an actual backing store. It simply accepts any items into the cache not actually storing them. Listing 10-21 shows a basic Spring configuration file declaring the NoOpCacheManager bean.

Listing 10-21. Spring configuration of NoOpCacheManager



Spring Framework CacheManager backed by a Gemfire Cache. Automatically discovers the created caches (or Regions in Gemfire terminology).

Listing 10-22. Spring configuration of GenFireCacheManager


Page Visitors: 13484

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

4 thoughts on “Spring Book – Chapter 10 – Caching

  1. 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.

    1. 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.. 🙂

      Tomcy John

  2. 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.


    1. 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.

      Tomcy John

Leave a Reply

Your email address will not be published. Required fields are marked *