Class AbstractCacheMissAware<T>
java.lang.Object
org.broadleafcommerce.common.cache.AbstractCacheMissAware<T>
- Direct Known Subclasses:
SystemPropertiesDaoImpl
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
Build the key representing this missed cache item.protected void
clearCache
(String cacheName) Remove all items from the underlying cache - a complete clearRetrieve the underlying cache for this query miss cache.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.protected abstract org.apache.commons.logging.Log
To provide more accurate logging, this abstract cache should utilize a logger from its child implementation.protected T
getNullObject
(Class<T> responseClass) Retrieve a null representation of the cache item.protected T
getObjectFromCache
(String key, String cacheName) Retrieve the missed cache item from the specified cache.protected void
removeItemFromCache
(String cacheName, String... params) Remove a specific cache item from the underlying cache
-
Field Details
-
statisticsService
-
cacheManager
protected javax.cache.CacheManager cacheManager
-
-
Constructor Details
-
AbstractCacheMissAware
public AbstractCacheMissAware()
-
-
Method Details
-
buildKey
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
Retrieve the missed cache item from the specified cache.- Parameters:
key
- the unique key for the cache itemcacheName
- the name of the cache - this is the cache region name from ehcache config- Returns:
- the cache item instance
-
getCache
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
Remove a specific cache item from the underlying cache- Parameters:
cacheName
- the name of the cache - the ehcache region nameparams
- the appropriate params comprising a unique key for this cache item
-
clearCache
Remove all items from the underlying cache - a complete clear- Parameters:
cacheName
- the name of the cache - the ehcache region name
-
getNullObject
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 itemcacheName
- the name of the cache - the ehcache region namestatisticsName
- the name to use for cache hit statisticsretrieval
- the block of code to execute if a cache miss is not found in this cacheparams
- 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
-