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: 11817