From ca6eee88dbcce7fd4f56f2aec3eb11552737f750 Mon Sep 17 00:00:00 2001 From: Daniel Stolt Date: Thu, 19 Mar 2015 21:15:25 +0100 Subject: [PATCH] Made output cache lock management more robust. --- .../Filters/OutputCacheFilter.cs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs b/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs index 1a610e361..992994f5e 100644 --- a/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs +++ b/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs @@ -165,11 +165,14 @@ namespace Orchard.OutputCache.Filters { } public void OnResultExecuted(ResultExecutedContext filterContext) { - if (!_isCachingRequest) - return; + + var captureHandlerIsAttached = false; try { + if (!_isCachingRequest) + return; + Logger.Debug("Item '{0}' was rendered.", _cacheKey); // Obtain individual route configuration, if any. @@ -232,14 +235,15 @@ namespace Orchard.OutputCache.Filters { ReleaseCacheKeyLock(); } }; + + captureHandlerIsAttached = true; } - catch { - // If an exception is caught, it means we were never able to attach the Captured - // event handler to the CaptureStream instance, because attaching that handler is - // the very last statement in the try block. Hence we can't assume that event - // handler to release the cache key lock, and we should do it here. - ReleaseCacheKeyLock(); - throw; + finally { + // If the response filter stream capture handler was attached then we'll trust + // it to release the cache key lock at some point in the future when the stream + // is flushed; otherwise we'll make sure we'll release it here. + if (!captureHandlerIsAttached) + ReleaseCacheKeyLock(); } }