Class EhcacheJCacheCacheManager

java.lang.Object
org.springframework.cache.support.AbstractCacheManager
org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager
org.springframework.cache.jcache.JCacheCacheManager
com.broadleafcommerce.common.extension.cache.ehcache.EhcacheJCacheCacheManager
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, org.springframework.cache.CacheManager

public class EhcacheJCacheCacheManager extends org.springframework.cache.jcache.JCacheCacheManager
Implementation of a CacheManager that integrates Ehcache and JCache operations and provides enhanced capabilities for deep cloning of cache values using a Cloner.

This class extends JCacheCacheManager and overrides certain behaviors to wrap JCacheCache with an EhcacheProxy that leverages a Cloner instance for deep cloning of cached objects. This ensures that cached data returned by the cache is not modified externally and maintains data integrity.

  • Constructor Summary

    Constructors
    Constructor
    Description
    EhcacheJCacheCacheManager(javax.cache.CacheManager cacheManager, Cloner cloner)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.springframework.cache.Cache
    decorateCache(org.springframework.cache.Cache cache)
    Overrides the default decoration logic to wrap JCacheCache instances with an EhcacheProxy.

    Methods inherited from class org.springframework.cache.jcache.JCacheCacheManager

    afterPropertiesSet, getCacheManager, getMissingCache, isAllowNullValues, loadCaches, setAllowNullValues, setCacheManager

    Methods inherited from class org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager

    isTransactionAware, setTransactionAware

    Methods inherited from class org.springframework.cache.support.AbstractCacheManager

    getCache, getCacheNames, initializeCaches, lookupCache

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EhcacheJCacheCacheManager

      public EhcacheJCacheCacheManager(javax.cache.CacheManager cacheManager, Cloner cloner)
  • Method Details

    • decorateCache

      @NonNull protected org.springframework.cache.Cache decorateCache(@NonNull org.springframework.cache.Cache cache)
      Overrides the default decoration logic to wrap JCacheCache instances with an EhcacheProxy.

      By using decorateCache instead of overriding getCache, we ensure that the proxying logic is applied only once when the cache is first initialized or added to the manager. This provides several benefits:

      • Performance: Avoids the overhead of creating new proxy and wrapper objects on every cache access.
      • Reference Equality: Ensures that subsequent calls to getCache return the same stable instance, which is critical for synchronization and metadata tracking.
      • Architectural Consistency: Leverages the superclass's built-in instance management and mapping.
      Overrides:
      decorateCache in class org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager
      Parameters:
      cache - the original cache instance to decorate
      Returns:
      the decorated cache, wrapped in an EhcacheProxy if it is a JCacheCache