From cce32f406f1a687206fda1470881c92bc60fb85a Mon Sep 17 00:00:00 2001 From: Stephan Date: Tue, 19 Mar 2013 17:50:36 -0100 Subject: [PATCH] Web.PublishedCache - move caches to UmbracoContext --- .../PublishedContentCacheTests.cs | 7 +++-- .../Routing/RenderRouteHandlerTests.cs | 4 +-- .../Routing/uQueryGetNodeIdByUrlTests.cs | 4 +-- .../TestHelpers/BaseDatabaseFactoryTest.cs | 5 +++- .../TestHelpers/BaseRoutingTest.cs | 4 +-- .../Routing/ContentFinderByIdPath.cs | 2 +- .../Routing/ContentFinderByLegacy404.cs | 2 +- .../Routing/ContentFinderByNiceUrl.cs | 4 +-- .../Routing/ContentFinderByNotFoundHandler.cs | 2 +- .../ContentFinderByNotFoundHandlers.cs | 2 +- .../Routing/ContentFinderByPageIdQuery.cs | 2 +- .../Routing/ContentFinderByUrlAlias.cs | 2 +- .../Routing/PublishedContentRequestEngine.cs | 6 ++-- src/Umbraco.Web/Routing/RoutingContext.cs | 8 ------ src/Umbraco.Web/Routing/UrlProvider.cs | 12 +++----- src/Umbraco.Web/Templates/TemplateRenderer.cs | 2 +- src/Umbraco.Web/UmbracoContext.cs | 28 +++++++++++++++---- src/Umbraco.Web/UmbracoModule.cs | 2 +- 18 files changed, 53 insertions(+), 45 deletions(-) diff --git a/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs index 117ed926dc..c0e8c75a9b 100644 --- a/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs +++ b/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs @@ -72,8 +72,11 @@ namespace Umbraco.Tests.PublishedCache //ensure the StateHelper is using our custom context StateHelper.HttpContext = _httpContextFactory.HttpContext; - _umbracoContext = new UmbracoContext(_httpContextFactory.HttpContext, - new ApplicationContext()); + _umbracoContext = new UmbracoContext( + _httpContextFactory.HttpContext, + new ApplicationContext(), + new PublishedContentCache(), + new PublishedMediaCache()); _umbracoContext.GetXmlDelegate = () => { diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index b13ecf488c..4c2bca139b 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -76,7 +76,7 @@ namespace Umbraco.Tests.Routing var routingContext = GetRoutingContext("~/dummy-page", template.Id, routeData); var docRequest = new PublishedContentRequest(routingContext.UmbracoContext.CleanedUmbracoUrl, routingContext) { - PublishedContent = routingContext.PublishedContentCache.GetById(routingContext.UmbracoContext, 1174), + PublishedContent = routingContext.UmbracoContext.ContentCache.GetById(routingContext.UmbracoContext, 1174), TemplateModel = template }; @@ -112,7 +112,7 @@ namespace Umbraco.Tests.Routing var routingContext = GetRoutingContext("~/dummy-page", template.Id, routeData, true); var docRequest = new PublishedContentRequest(routingContext.UmbracoContext.CleanedUmbracoUrl, routingContext) { - PublishedContent = routingContext.PublishedContentCache.GetById(routingContext.UmbracoContext, 1172), + PublishedContent = routingContext.UmbracoContext.ContentCache.GetById(routingContext.UmbracoContext, 1172), TemplateModel = template }; diff --git a/src/Umbraco.Tests/Routing/uQueryGetNodeIdByUrlTests.cs b/src/Umbraco.Tests/Routing/uQueryGetNodeIdByUrlTests.cs index 46d7699bdb..b667ae332f 100644 --- a/src/Umbraco.Tests/Routing/uQueryGetNodeIdByUrlTests.cs +++ b/src/Umbraco.Tests/Routing/uQueryGetNodeIdByUrlTests.cs @@ -34,13 +34,11 @@ namespace Umbraco.Tests.Routing var t = Template.MakeNew("test", new User(0)); var umbracoContext = GetUmbracoContext(url, t.Id); - var cache = new PublishedContentCache(); - var urlProvider = new UrlProvider(umbracoContext, cache, new IUrlProvider[] { new DefaultUrlProvider() }); + var urlProvider = new UrlProvider(umbracoContext, new IUrlProvider[] { new DefaultUrlProvider() }); var routingContext = new RoutingContext( umbracoContext, lookups, new FakeLastChanceFinder(), - cache, urlProvider, GetRoutesCache()); diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs index a9209cf9c9..e9a32661f6 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs @@ -21,6 +21,7 @@ using Umbraco.Core.Publishing; using Umbraco.Core.Services; using Umbraco.Tests.Stubs; using Umbraco.Web; +using Umbraco.Web.PublishedCache.LegacyXmlCache; using Umbraco.Web.Routing; using umbraco.BusinessLogic; @@ -279,7 +280,9 @@ namespace Umbraco.Tests.TestHelpers { var ctx = new UmbracoContext( GetHttpContextFactory(url, routeData).HttpContext, - ApplicationContext); + ApplicationContext, + new PublishedContentCache(), + new PublishedMediaCache()); SetupUmbracoContextForTest(ctx, templateId); return ctx; } diff --git a/src/Umbraco.Tests/TestHelpers/BaseRoutingTest.cs b/src/Umbraco.Tests/TestHelpers/BaseRoutingTest.cs index 36cc8c6bf9..7eb02a9d74 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseRoutingTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseRoutingTest.cs @@ -28,13 +28,11 @@ namespace Umbraco.Tests.TestHelpers protected RoutingContext GetRoutingContext(string url, int templateId, RouteData routeData = null, bool setUmbracoContextCurrent = false) { var umbracoContext = GetUmbracoContext(url, templateId, routeData); - var cache = new PublishedContentCache(); - var urlProvider = new UrlProvider(umbracoContext, cache, new IUrlProvider[] { new DefaultUrlProvider() }); + var urlProvider = new UrlProvider(umbracoContext, new IUrlProvider[] { new DefaultUrlProvider() }); var routingContext = new RoutingContext( umbracoContext, Enumerable.Empty(), new FakeLastChanceFinder(), - cache, urlProvider, GetRoutesCache()); diff --git a/src/Umbraco.Web/Routing/ContentFinderByIdPath.cs b/src/Umbraco.Web/Routing/ContentFinderByIdPath.cs index 57f0dd9d89..a7f1bf7bf3 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByIdPath.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByIdPath.cs @@ -34,7 +34,7 @@ namespace Umbraco.Web.Routing if (nodeId > 0) { LogHelper.Debug("Id={0}", () => nodeId); - node = docRequest.RoutingContext.PublishedContentCache.GetById( + node = docRequest.RoutingContext.UmbracoContext.ContentCache.GetById( docRequest.RoutingContext.UmbracoContext, nodeId); diff --git a/src/Umbraco.Web/Routing/ContentFinderByLegacy404.cs b/src/Umbraco.Web/Routing/ContentFinderByLegacy404.cs index 653cfa702b..8d4c63964d 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByLegacy404.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByLegacy404.cs @@ -27,7 +27,7 @@ namespace Umbraco.Web.Routing { LogHelper.Debug("Got id={0}.", () => id); - content = pcr.RoutingContext.PublishedContentCache.GetById( + content = pcr.RoutingContext.UmbracoContext.ContentCache.GetById( pcr.RoutingContext.UmbracoContext, id); diff --git a/src/Umbraco.Web/Routing/ContentFinderByNiceUrl.cs b/src/Umbraco.Web/Routing/ContentFinderByNiceUrl.cs index 427bb4500b..ed0d155f74 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByNiceUrl.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByNiceUrl.cs @@ -66,7 +66,7 @@ namespace Umbraco.Web.Routing IPublishedContent node = null; if (nodeId > 0) { - node = docreq.RoutingContext.PublishedContentCache.GetById( + node = docreq.RoutingContext.UmbracoContext.ContentCache.GetById( docreq.RoutingContext.UmbracoContext, nodeId); @@ -85,7 +85,7 @@ namespace Umbraco.Web.Routing if (node == null) { LogHelper.Debug("Cache miss, query"); - node = docreq.RoutingContext.PublishedContentCache.GetByRoute( + node = docreq.RoutingContext.UmbracoContext.ContentCache.GetByRoute( docreq.RoutingContext.UmbracoContext, route); diff --git a/src/Umbraco.Web/Routing/ContentFinderByNotFoundHandler.cs b/src/Umbraco.Web/Routing/ContentFinderByNotFoundHandler.cs index 3b824825e7..de53583062 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByNotFoundHandler.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByNotFoundHandler.cs @@ -30,7 +30,7 @@ namespace Umbraco.Web.Routing { LogHelper.Debug>("Handler '{0}' returned id={1}.", () => type.FullName, () => handler.redirectID); - var content = pcr.RoutingContext.PublishedContentCache.GetById( + var content = pcr.RoutingContext.UmbracoContext.ContentCache.GetById( pcr.RoutingContext.UmbracoContext, handler.redirectID); diff --git a/src/Umbraco.Web/Routing/ContentFinderByNotFoundHandlers.cs b/src/Umbraco.Web/Routing/ContentFinderByNotFoundHandlers.cs index ee64578e5e..efd83ca415 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByNotFoundHandlers.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByNotFoundHandlers.cs @@ -76,7 +76,7 @@ namespace Umbraco.Web.Routing if (handler.Execute(url) && handler.redirectID > 0) { var redirectId = handler.redirectID; - docRequest.PublishedContent = docRequest.RoutingContext.PublishedContentCache.GetById( + docRequest.PublishedContent = docRequest.RoutingContext.UmbracoContext.ContentCache.GetById( docRequest.RoutingContext.UmbracoContext, redirectId); diff --git a/src/Umbraco.Web/Routing/ContentFinderByPageIdQuery.cs b/src/Umbraco.Web/Routing/ContentFinderByPageIdQuery.cs index a6cb2da50c..10a85ae0d6 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByPageIdQuery.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByPageIdQuery.cs @@ -14,7 +14,7 @@ namespace Umbraco.Web.Routing int pageId; if (int.TryParse(docRequest.RoutingContext.UmbracoContext.HttpContext.Request["umbPageID"], out pageId)) { - var doc = docRequest.RoutingContext.PublishedContentCache.GetById( + var doc = docRequest.RoutingContext.UmbracoContext.ContentCache.GetById( docRequest.RoutingContext.UmbracoContext, pageId); diff --git a/src/Umbraco.Web/Routing/ContentFinderByUrlAlias.cs b/src/Umbraco.Web/Routing/ContentFinderByUrlAlias.cs index 67422da605..bff69b24c0 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByUrlAlias.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByUrlAlias.cs @@ -24,7 +24,7 @@ namespace Umbraco.Web.Routing if (docRequest.Uri.AbsolutePath != "/") // no alias if "/" { - node = docRequest.RoutingContext.PublishedContentCache.GetByUrlAlias( + node = docRequest.RoutingContext.UmbracoContext.ContentCache.GetByUrlAlias( docRequest.RoutingContext.UmbracoContext, docRequest.HasDomain ? docRequest.Domain.RootNodeId : 0, docRequest.Uri.GetAbsolutePathDecoded()); diff --git a/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs b/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs index ca6ef63818..177a90ad42 100644 --- a/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs +++ b/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs @@ -444,7 +444,7 @@ namespace Umbraco.Web.Routing else { // redirect to another page - var node = _routingContext.PublishedContentCache.GetById(_routingContext.UmbracoContext, internalRedirectId); + var node = _routingContext.UmbracoContext.ContentCache.GetById(_routingContext.UmbracoContext, internalRedirectId); _pcr.SetInternalRedirectPublishedContent(node); // don't use .PublishedContent here if (node != null) @@ -494,14 +494,14 @@ namespace Umbraco.Web.Routing LogHelper.Debug("{0}Not logged in, redirect to login page", () => tracePrefix); var loginPageId = Access.GetLoginPage(path); if (loginPageId != _pcr.PublishedContent.Id) - _pcr.PublishedContent = _routingContext.PublishedContentCache.GetById(_routingContext.UmbracoContext, loginPageId); + _pcr.PublishedContent = _routingContext.UmbracoContext.ContentCache.GetById(_routingContext.UmbracoContext, loginPageId); } else if (!Access.HasAccces(_pcr.PublishedContent.Id, user.ProviderUserKey)) { LogHelper.Debug("{0}Current member has not access, redirect to error page", () => tracePrefix); var errorPageId = Access.GetErrorPage(path); if (errorPageId != _pcr.PublishedContent.Id) - _pcr.PublishedContent = _routingContext.PublishedContentCache.GetById(_routingContext.UmbracoContext, errorPageId); + _pcr.PublishedContent = _routingContext.UmbracoContext.ContentCache.GetById(_routingContext.UmbracoContext, errorPageId); } else { diff --git a/src/Umbraco.Web/Routing/RoutingContext.cs b/src/Umbraco.Web/Routing/RoutingContext.cs index 25d776d21b..ed01f1e260 100644 --- a/src/Umbraco.Web/Routing/RoutingContext.cs +++ b/src/Umbraco.Web/Routing/RoutingContext.cs @@ -15,21 +15,18 @@ namespace Umbraco.Web.Routing /// /// The document lookups resolver. /// - /// The content store. /// The nice urls provider. /// The routes cache. internal RoutingContext( UmbracoContext umbracoContext, IEnumerable contentFinders, IContentFinder contentLastChanceFinder, - IPublishedContentCache contentCache, UrlProvider urlProvider, IRoutesCache routesCache) { UmbracoContext = umbracoContext; PublishedContentFinders = contentFinders; PublishedContentLastChanceFinder = contentLastChanceFinder; - PublishedContentCache = contentCache; UrlProvider = urlProvider; RoutesCache = routesCache; } @@ -49,11 +46,6 @@ namespace Umbraco.Web.Routing /// internal IContentFinder PublishedContentLastChanceFinder { get; private set; } - /// - /// Gets the published content cache. - /// - internal IPublishedContentCache PublishedContentCache { get; private set; } - /// /// Gets the urls provider. /// diff --git a/src/Umbraco.Web/Routing/UrlProvider.cs b/src/Umbraco.Web/Routing/UrlProvider.cs index 11a871e4b0..d658e1eff7 100644 --- a/src/Umbraco.Web/Routing/UrlProvider.cs +++ b/src/Umbraco.Web/Routing/UrlProvider.cs @@ -14,22 +14,18 @@ namespace Umbraco.Web.Routing #region Ctor and configuration /// - /// Initializes a new instance of the class with an Umbraco context, a content cache, and a list of url providers. + /// Initializes a new instance of the class with an Umbraco context and a list of url providers. /// /// The Umbraco context. - /// The content cache. /// The list of url providers. - public UrlProvider(UmbracoContext umbracoContext, IPublishedContentCache contentCache, - IEnumerable urlProviders) + public UrlProvider(UmbracoContext umbracoContext, IEnumerable urlProviders) { _umbracoContext = umbracoContext; - _contentCache = contentCache; _urlProviders = urlProviders; Mode = UmbracoSettings.For().UrlProviderMode; } private readonly UmbracoContext _umbracoContext; - private readonly IPublishedContentCache _contentCache; private readonly IEnumerable _urlProviders; /// @@ -118,7 +114,7 @@ namespace Umbraco.Web.Routing /// public string GetUrl(int id, Uri current, UrlProviderMode mode) { - var url = _urlProviders.Select(provider => provider.GetUrl(_umbracoContext, _contentCache, id, current, mode)) + var url = _urlProviders.Select(provider => provider.GetUrl(_umbracoContext, _umbracoContext.ContentCache, id, current, mode)) .FirstOrDefault(u => u != null); return url ?? "#"; // legacy wants this } @@ -155,7 +151,7 @@ namespace Umbraco.Web.Routing public IEnumerable GetOtherUrls(int id, Uri current) { // providers can return null or an empty list or a non-empty list, be prepared - var urls = _urlProviders.SelectMany(provider => provider.GetOtherUrls(_umbracoContext, _contentCache, id, current) ?? Enumerable.Empty()); + var urls = _urlProviders.SelectMany(provider => provider.GetOtherUrls(_umbracoContext, _umbracoContext.ContentCache, id, current) ?? Enumerable.Empty()); return urls; } diff --git a/src/Umbraco.Web/Templates/TemplateRenderer.cs b/src/Umbraco.Web/Templates/TemplateRenderer.cs index cc7dc97164..d5abcc6ee7 100644 --- a/src/Umbraco.Web/Templates/TemplateRenderer.cs +++ b/src/Umbraco.Web/Templates/TemplateRenderer.cs @@ -54,7 +54,7 @@ namespace Umbraco.Web.Templates // terribly much for this implementation since we are just creating a doc content request to modify it's properties manually. var contentRequest = new PublishedContentRequest(_umbracoContext.CleanedUmbracoUrl, _umbracoContext.RoutingContext); - var doc = contentRequest.RoutingContext.PublishedContentCache.GetById( + var doc = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetById( contentRequest.RoutingContext.UmbracoContext, PageId); diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index e9dc7f1b31..53aea8c6ca 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -25,7 +25,6 @@ namespace Umbraco.Web /// public class UmbracoContext { - private const string HttpContextItemName = "Umbraco.Web.UmbracoContext"; private static readonly object Locker = new object(); @@ -82,13 +81,16 @@ namespace Umbraco.Web if (UmbracoContext.Current != null && !replaceContext) return UmbracoContext.Current; - var umbracoContext = new UmbracoContext(httpContext, applicationContext); + var umbracoContext = new UmbracoContext( + httpContext, + applicationContext, + PublishedContentCacheResolver.Current.PublishedContentCache, + PublishedMediaCacheResolver.Current.PublishedMediaCache); // create the nice urls provider // there's one per request because there are some behavior parameters that can be changed var urlProvider = new UrlProvider( umbracoContext, - PublishedContentCacheResolver.Current.PublishedContentCache, UrlProviderResolver.Current.Providers); // create the RoutingContext, and assign @@ -96,7 +98,6 @@ namespace Umbraco.Web umbracoContext, ContentFinderResolver.Current.Finders, ContentLastChanceFinderResolver.Current.Finder, - PublishedContentCacheResolver.Current.PublishedContentCache, urlProvider, RoutesCacheResolver.Current.RoutesCache); @@ -113,9 +114,13 @@ namespace Umbraco.Web /// /// /// + /// The published content cache. + /// The published media cache. internal UmbracoContext( HttpContextBase httpContext, - ApplicationContext applicationContext) + ApplicationContext applicationContext, + IPublishedContentCache contentCache, + IPublishedMediaCache mediaCache) { if (httpContext == null) throw new ArgumentNullException("httpContext"); if (applicationContext == null) throw new ArgumentNullException("applicationContext"); @@ -126,6 +131,9 @@ namespace Umbraco.Web HttpContext = httpContext; Application = applicationContext; + ContentCache = contentCache; + MediaCache = mediaCache; + // set the urls... //original request url //NOTE: The request will not be available during app startup so we can only set this to an absolute URL of localhost, this @@ -214,6 +222,16 @@ namespace Umbraco.Web /// That is, lowercase, no trailing slash after path, no .aspx... internal Uri CleanedUmbracoUrl { get; private set; } + /// + /// Gets or sets the published content cache. + /// + internal IPublishedContentCache ContentCache { get; private set; } + + /// + /// Gets or sets the published media cache. + /// + internal IPublishedMediaCache MediaCache { get; private set; } + private Func _xmlDelegate; /// diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index f8a05e57e7..36ed373b70 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -317,7 +317,7 @@ namespace Umbraco.Web // if yes, return true private static bool EnsureHasContent(UmbracoContext context, HttpContextBase httpContext) { - var store = context.RoutingContext.PublishedContentCache; + var store = context.RoutingContext.UmbracoContext.ContentCache; if (store.HasContent(context)) return true;