U4-9337 - asymmetric route caching

This commit is contained in:
Stephan
2017-01-06 09:12:25 +01:00
parent 89be1cf5d2
commit aadd0c9129
6 changed files with 138 additions and 49 deletions

View File

@@ -2,11 +2,9 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
@@ -18,7 +16,6 @@ using umbraco.BusinessLogic;
using umbraco.presentation.preview;
using Umbraco.Core.Services;
using GlobalSettings = umbraco.GlobalSettings;
using Task = System.Threading.Tasks.Task;
namespace Umbraco.Web.PublishedCache.XmlPublishedCache
{
@@ -83,7 +80,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
&& DomainHelper.ExistsDomainInPath(umbracoContext.Application.Services.DomainService.GetAll(false), content.Path, domainRootNodeId) == false;
if (deepest)
_routesCache.Store(content.Id, route);
_routesCache.Store(content.Id, route, true); // trusted route
}
public virtual string GetRouteById(UmbracoContext umbracoContext, bool preview, int contentId)
@@ -98,9 +95,16 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
// else actually determine the route
route = DetermineRouteById(umbracoContext, preview, contentId);
// may be null if node not found
// do NOT cache the route: it may be colliding - and since checking for a collision implies
// doing one DetermineIdByRoute anyways we are not causing any perf penalty by not caching
// node not found
if (route == null)
return null;
// cache the route BUT do NOT trust it as it can be a colliding route
// meaning if we GetRouteById again, we'll get it from cache, but it
// won't be used for inbound routing
if (preview == false)
_routesCache.Store(contentId, route, false);
return route;
}

View File

@@ -83,10 +83,12 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
/// </summary>
/// <param name="nodeId">The node identified.</param>
/// <param name="route">The route.</param>
public void Store(int nodeId, string route)
/// <param name="trust">A value indicating whether the value can be trusted for inbound routing.</param>
public void Store(int nodeId, string route, bool trust)
{
_routes.AddOrUpdate(nodeId, i => route, (i, s) => route);
_nodeIds.AddOrUpdate(route, i => nodeId, (i, s) => nodeId);
if (trust)
_nodeIds.AddOrUpdate(route, i => nodeId, (i, s) => nodeId);
}
/// <summary>
@@ -119,15 +121,12 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
/// <param name="nodeId">The node identifier.</param>
public void ClearNode(int nodeId)
{
if (!_routes.ContainsKey(nodeId)) return;
string key;
if (!_routes.TryGetValue(nodeId, out key)) return;
int val;
_nodeIds.TryRemove(key, out val);
string val2;
_routes.TryRemove(nodeId, out val2);
string route;
if (_routes.TryRemove(nodeId, out route))
{
int id;
_nodeIds.TryRemove(route, out id);
}
}
/// <summary>