Handling output cache provider exceptions

This commit is contained in:
Sebastien Ros
2015-08-04 10:29:46 -07:00
parent 8a08680a74
commit bb6a44634d

View File

@@ -109,7 +109,7 @@ namespace Orchard.OutputCache.Filters {
// Is there a cached item, and are we allowed to serve it?
var allowServeFromCache = filterContext.RequestContext.HttpContext.Request.Headers["Cache-Control"] != "no-cache" || CacheSettings.IgnoreNoCache;
var cacheItem = _cacheStorageProvider.GetCacheItem(_cacheKey);
var cacheItem = GetCacheItem(_cacheKey);
if (allowServeFromCache && cacheItem != null) {
Logger.Debug("Item '{0}' was found in cache.", _cacheKey);
@@ -140,7 +140,7 @@ namespace Orchard.OutputCache.Filters {
// Item might now have been rendered and cached by another request; if so serve it from cache.
if (allowServeFromCache) {
cacheItem = _cacheStorageProvider.GetCacheItem(_cacheKey);
cacheItem = GetCacheItem(_cacheKey);
if (cacheItem != null) {
Logger.Debug("Item '{0}' was now found; releasing cache key lock and serving from cache.", _cacheKey);
Monitor.Exit(cacheKeyLock);
@@ -591,6 +591,18 @@ namespace Orchard.OutputCache.Filters {
return keyBuilder.ToString();
}
protected virtual CacheItem GetCacheItem(string key) {
try {
var cacheItem = _cacheStorageProvider.GetCacheItem(key);
return cacheItem;
}
catch(Exception e) {
Logger.Error(e, "An unexpected error occured while reading a cache entry");
}
return null;
}
}
public class ViewDataContainer : IViewDataContainer {