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: 13097
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
4 thoughts on “Spring Book – Chapter 10 – Caching”
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.. 🙂
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.
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.