Replaced usages of HttpContext.Items with usages of IRequestCache

This commit is contained in:
Bjarke Berg
2020-02-13 07:46:49 +01:00
parent 6f32470fdf
commit 85afde0ea1
24 changed files with 152 additions and 140 deletions

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Web;
using System.Web.Routing;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
@@ -38,6 +39,7 @@ namespace Umbraco.Web
private readonly IPublishedRouter _publishedRouter;
private readonly IUmbracoContextFactory _umbracoContextFactory;
private readonly RoutableDocumentFilter _routableDocumentLookup;
private readonly IRequestCache _requestCache;
public UmbracoInjectedModule(
IGlobalSettings globalSettings,
@@ -45,7 +47,8 @@ namespace Umbraco.Web
ILogger logger,
IPublishedRouter publishedRouter,
IUmbracoContextFactory umbracoContextFactory,
RoutableDocumentFilter routableDocumentLookup)
RoutableDocumentFilter routableDocumentLookup,
IRequestCache requestCache)
{
_globalSettings = globalSettings;
_runtime = runtime;
@@ -53,6 +56,7 @@ namespace Umbraco.Web
_publishedRouter = publishedRouter;
_umbracoContextFactory = umbracoContextFactory;
_routableDocumentLookup = routableDocumentLookup;
_requestCache = requestCache;
}
#region HttpModule event handlers
@@ -305,15 +309,15 @@ namespace Umbraco.Web
/// Any object that is in the HttpContext.Items collection that is IDisposable will get disposed on the end of the request
/// </summary>
/// <param name="http"></param>
private void DisposeHttpContextItems(HttpContext http)
private void DisposeRequestCacheItems(HttpContext http, IRequestCache requestCache)
{
// do not process if client-side request
if (http.Request.Url.IsClientSideRequest())
return;
//get a list of keys to dispose
var keys = new HashSet<object>();
foreach (DictionaryEntry i in http.Items)
var keys = new HashSet<string>();
foreach (var i in requestCache)
{
if (i.Value is IDisposeOnRequestEnd || i.Key is IDisposeOnRequestEnd)
{
@@ -325,7 +329,7 @@ namespace Umbraco.Web
{
try
{
http.Items[k].DisposeIfDisposable();
requestCache.Get(k).DisposeIfDisposable();
}
catch (Exception ex)
{
@@ -376,7 +380,7 @@ namespace Umbraco.Web
{
var httpContext = ((HttpApplication) sender).Context;
LogHttpRequest.TryGetCurrentHttpRequestId(out var httpRequestId, Current.AppCaches.RequestCache);
LogHttpRequest.TryGetCurrentHttpRequestId(out var httpRequestId, _requestCache);
_logger.Verbose<UmbracoModule>("Begin request [{HttpRequestId}]: {RequestUrl}", httpRequestId, httpContext.Request.Url);
BeginRequest(new HttpContextWrapper(httpContext));
@@ -421,14 +425,14 @@ namespace Umbraco.Web
if (Current.UmbracoContext != null && Current.UmbracoContext.IsFrontEndUmbracoRequest)
{
LogHttpRequest.TryGetCurrentHttpRequestId(out var httpRequestId, Current.AppCaches.RequestCache);
LogHttpRequest.TryGetCurrentHttpRequestId(out var httpRequestId, _requestCache);
_logger.Verbose<UmbracoModule>("End Request [{HttpRequestId}]: {RequestUrl} ({RequestDuration}ms)", httpRequestId, httpContext.Request.Url, DateTime.Now.Subtract(Current.UmbracoContext.ObjectCreated).TotalMilliseconds);
}
UmbracoModule.OnEndRequest(this, new UmbracoRequestEventArgs(Current.UmbracoContext, new HttpContextWrapper(httpContext)));
DisposeHttpContextItems(httpContext);
DisposeRequestCacheItems(httpContext, _requestCache);
};
}