Web.PublishedCache - move caches to UmbracoContext

This commit is contained in:
Stephan
2013-03-19 17:50:36 -01:00
parent ef9ce720b2
commit cce32f406f
18 changed files with 53 additions and 45 deletions

View File

@@ -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 = () =>
{

View File

@@ -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
};

View File

@@ -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());

View File

@@ -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;
}

View File

@@ -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<IContentFinder>(),
new FakeLastChanceFinder(),
cache,
urlProvider,
GetRoutesCache());

View File

@@ -34,7 +34,7 @@ namespace Umbraco.Web.Routing
if (nodeId > 0)
{
LogHelper.Debug<ContentFinderByIdPath>("Id={0}", () => nodeId);
node = docRequest.RoutingContext.PublishedContentCache.GetById(
node = docRequest.RoutingContext.UmbracoContext.ContentCache.GetById(
docRequest.RoutingContext.UmbracoContext,
nodeId);

View File

@@ -27,7 +27,7 @@ namespace Umbraco.Web.Routing
{
LogHelper.Debug<ContentFinderByLegacy404>("Got id={0}.", () => id);
content = pcr.RoutingContext.PublishedContentCache.GetById(
content = pcr.RoutingContext.UmbracoContext.ContentCache.GetById(
pcr.RoutingContext.UmbracoContext,
id);

View File

@@ -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<ContentFinderByNiceUrl>("Cache miss, query");
node = docreq.RoutingContext.PublishedContentCache.GetByRoute(
node = docreq.RoutingContext.UmbracoContext.ContentCache.GetByRoute(
docreq.RoutingContext.UmbracoContext,
route);

View File

@@ -30,7 +30,7 @@ namespace Umbraco.Web.Routing
{
LogHelper.Debug<ContentFinderByNotFoundHandler<THandler>>("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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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());

View File

@@ -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<PublishedContentRequestEngine>("{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<PublishedContentRequestEngine>("{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
{

View File

@@ -15,21 +15,18 @@ namespace Umbraco.Web.Routing
/// <param name="umbracoContext"> </param>
/// <param name="contentFinders">The document lookups resolver.</param>
/// <param name="contentLastChanceFinder"> </param>
/// <param name="contentCache">The content store.</param>
/// <param name="urlProvider">The nice urls provider.</param>
/// <param name="routesCache">The routes cache.</param>
internal RoutingContext(
UmbracoContext umbracoContext,
IEnumerable<IContentFinder> 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
/// </summary>
internal IContentFinder PublishedContentLastChanceFinder { get; private set; }
/// <summary>
/// Gets the published content cache.
/// </summary>
internal IPublishedContentCache PublishedContentCache { get; private set; }
/// <summary>
/// Gets the urls provider.
/// </summary>

View File

@@ -14,22 +14,18 @@ namespace Umbraco.Web.Routing
#region Ctor and configuration
/// <summary>
/// Initializes a new instance of the <see cref="UrlProvider"/> class with an Umbraco context, a content cache, and a list of url providers.
/// Initializes a new instance of the <see cref="UrlProvider"/> class with an Umbraco context and a list of url providers.
/// </summary>
/// <param name="umbracoContext">The Umbraco context.</param>
/// <param name="contentCache">The content cache.</param>
/// <param name="urlProviders">The list of url providers.</param>
public UrlProvider(UmbracoContext umbracoContext, IPublishedContentCache contentCache,
IEnumerable<IUrlProvider> urlProviders)
public UrlProvider(UmbracoContext umbracoContext, IEnumerable<IUrlProvider> urlProviders)
{
_umbracoContext = umbracoContext;
_contentCache = contentCache;
_urlProviders = urlProviders;
Mode = UmbracoSettings.For<Configuration.WebRouting>().UrlProviderMode;
}
private readonly UmbracoContext _umbracoContext;
private readonly IPublishedContentCache _contentCache;
private readonly IEnumerable<IUrlProvider> _urlProviders;
/// <summary>
@@ -118,7 +114,7 @@ namespace Umbraco.Web.Routing
/// </remarks>
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<string> 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<string>());
var urls = _urlProviders.SelectMany(provider => provider.GetOtherUrls(_umbracoContext, _umbracoContext.ContentCache, id, current) ?? Enumerable.Empty<string>());
return urls;
}

View File

@@ -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);

View File

@@ -25,7 +25,6 @@ namespace Umbraco.Web
/// </summary>
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
/// </summary>
/// <param name="httpContext"></param>
/// <param name="applicationContext"> </param>
/// <param name="contentCache">The published content cache.</param>
/// <param name="mediaCache">The published media cache.</param>
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
/// <remarks>That is, lowercase, no trailing slash after path, no .aspx...</remarks>
internal Uri CleanedUmbracoUrl { get; private set; }
/// <summary>
/// Gets or sets the published content cache.
/// </summary>
internal IPublishedContentCache ContentCache { get; private set; }
/// <summary>
/// Gets or sets the published media cache.
/// </summary>
internal IPublishedMediaCache MediaCache { get; private set; }
private Func<XmlDocument> _xmlDelegate;
/// <summary>

View File

@@ -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;