Class AbstractCacheMissAware<T>

java.lang.Object
org.broadleafcommerce.common.cache.AbstractCacheMissAware<T>
Direct Known Subclasses:
SystemPropertiesDaoImpl

public abstract class AbstractCacheMissAware<T> extends Object
Support for any class that wishes to utilize a query miss cache. This cache is capable of caching a query miss (the query returns no results). This is beneficial since standard level 2 cache does not maintain misses.

NOTE, special cache invalidation support must be added to address this cache if a change is made to one or more of the cached missed items.

Author:
Jeff Fischer
  • Field Details

    • statisticsService

      protected StatisticsService statisticsService
    • cacheManager

      protected javax.cache.CacheManager cacheManager
  • Constructor Details

    • AbstractCacheMissAware

      public AbstractCacheMissAware()
  • Method Details

    • buildKey

      protected String buildKey(String... params)
      Build the key representing this missed cache item. Will include sandbox and/or site information if appropriate.
      Parameters:
      params - the appropriate params comprising a unique key for this cache item
      Returns:
      the completed key
    • getObjectFromCache

      protected T getObjectFromCache(String key, String cacheName)
      Retrieve the missed cache item from the specified cache.
      Parameters:
      key - the unique key for the cache item
      cacheName - the name of the cache - this is the cache region name from ehcache config
      Returns:
      the cache item instance
    • getCache

      protected javax.cache.Cache<String,T> getCache(String cacheName)
      Retrieve the underlying cache for this query miss cache. Presumably and Ehcache region has been configured for this cacheName.
      Parameters:
      cacheName - the name of the cache - the ehcache region name
      Returns:
      the underlying cache
    • removeItemFromCache

      protected void removeItemFromCache(String cacheName, String... params)
      Remove a specific cache item from the underlying cache
      Parameters:
      cacheName - the name of the cache - the ehcache region name
      params - the appropriate params comprising a unique key for this cache item
    • clearCache

      protected void clearCache(String cacheName)
      Remove all items from the underlying cache - a complete clear
      Parameters:
      cacheName - the name of the cache - the ehcache region name
    • getNullObject

      protected T getNullObject(Class<T> responseClass)
      Retrieve a null representation of the cache item. This representation is the same for all cache misses and is used as the object representation to store in the cache for a cache miss.
      Parameters:
      responseClass - the class representing the type of the cache item
      Returns:
      the null representation for the cache item
    • getCachedObject

      protected T getCachedObject(Class<T> responseClass, String cacheName, String statisticsName, PersistentRetrieval<T> retrieval, String... params)
      This is the main entry point for retrieving an object from this cache.
      Parameters:
      responseClass - the class representing the type of the cache item
      cacheName - the name of the cache - the ehcache region name
      statisticsName - the name to use for cache hit statistics
      retrieval - the block of code to execute if a cache miss is not found in this cache
      params - the appropriate params comprising a unique key for this cache item
      Returns:
      The object retrieved from the executiom of the PersistentRetrieval, or null if a cache miss was found in this cache
      See Also:
    • getLogger

      protected abstract org.apache.commons.logging.Log getLogger()
      To provide more accurate logging, this abstract cache should utilize a logger from its child implementation.
      Returns:
      a Log instance from the subclass of this abstract class