Skip to content

Commit 4f2d69a

Browse files
committed
Slight modification on the code to reduce nesting and improve readability.
1 parent f00a4a6 commit 4f2d69a

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

DevTrends.MvcDonutCaching/DonutOutputCacheAttribute.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,22 @@ public override void OnActionExecuting(ActionExecutingContext filterContext)
7979

8080
filterContext.HttpContext.Response.Output = originalWriter;
8181

82-
if (!hasErrors)
82+
if (hasErrors)
8383
{
84-
var cacheItem = new CacheItem
85-
{
86-
Content = cachingWriter.ToString(),
87-
ContentType = filterContext.HttpContext.Response.ContentType
88-
};
89-
90-
filterContext.HttpContext.Response.Write(_donutHoleFiller.RemoveDonutHoleWrappers(cacheItem.Content, filterContext));
91-
92-
if (_cacheSettings.IsServerCachingEnabled && filterContext.HttpContext.Response.StatusCode == 200)
93-
{
94-
_outputCacheManager.AddItem(cacheKey, cacheItem, DateTime.UtcNow.AddSeconds(_cacheSettings.Duration));
95-
}
84+
return;
85+
}
86+
87+
var cacheItem = new CacheItem
88+
{
89+
Content = cachingWriter.ToString(),
90+
ContentType = filterContext.HttpContext.Response.ContentType
91+
};
92+
93+
filterContext.HttpContext.Response.Write(_donutHoleFiller.RemoveDonutHoleWrappers(cacheItem.Content, filterContext));
94+
95+
if (_cacheSettings.IsServerCachingEnabled && filterContext.HttpContext.Response.StatusCode == 200)
96+
{
97+
_outputCacheManager.AddItem(cacheKey, cacheItem, DateTime.UtcNow.AddSeconds(_cacheSettings.Duration));
9698
}
9799
});
98100
}

0 commit comments

Comments
 (0)