* @param <T> the type of the cache item
* @return The object retrieved from the executiom of the PersistentRetrieval, or null if a cache miss was found in this cache
*/
protected <T> T getCachedObject(Class<T> responseClass, String cacheName, String statisticsName, PersistentRetrieval<T> retrieval, String... params) {
T nullResponse = getNullObject(responseClass);
BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
String key = buildKey(params);
T response = null;
if (context.isProductionSandBox()) {
response = getObjectFromCache(key, cacheName);
}
if (response == null) {
response = retrieval.retrievePersistentObject();
if (response == null) {
response = nullResponse;
}
//only handle null, non-hits. Otherwise, let level 2 cache handle it
if (context.isProductionSandBox() && response.equals(nullResponse)) {
statisticsService.addCacheStat(statisticsName, false);
getCache(cacheName).put(new Element(key, response));
if (getLogger().isTraceEnabled()) {
getLogger().trace("Caching [" + key + "] as null in the [" + cacheName + "] cache.");
}