diff --git a/src/Umbraco.Tests/Cache/HttpRequestCacheProviderTests.cs b/src/Umbraco.Tests/Cache/HttpRequestCacheProviderTests.cs index 87a468ddd5..d16af8433a 100644 --- a/src/Umbraco.Tests/Cache/HttpRequestCacheProviderTests.cs +++ b/src/Umbraco.Tests/Cache/HttpRequestCacheProviderTests.cs @@ -1,9 +1,26 @@ using NUnit.Framework; using Umbraco.Core.Cache; +using umbraco.presentation.webservices; using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.Cache { + [TestFixture] + public class CacheRefresherTests + { + [TestCase("", "123456", "testmachine", true)] //empty hash will continue + [TestCase("2c8aabac795d189d444a9cdc6e2a1819", "123456", "testmachine", false)] //match, don't continue + [TestCase("2c8aabac795d189d444a9cdc6e2a1819", "12345", "testmachine", true)] + [TestCase("2c8aabac795d189d444a9cdc6e2a1819", "123456", "testmachin", true)] + [TestCase("2c8aabac795d189d444a9cdc6e2a181", "123456", "testmachine", true)] + public void Continue_Refreshing_For_Request(string hash, string appDomainAppId, string machineName, bool expected) + { + var refresher = new CacheRefresher(); + Assert.AreEqual(expected, refresher.ContinueRefreshingForRequest(hash, appDomainAppId, machineName)); + } + + } + [TestFixture] public class HttpRequestCacheProviderTests : CacheProviderTests { diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index c458ee63c3..64be93bb9a 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -139,6 +139,7 @@ True + True ..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.dll diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx.cs index 6939d9b155..224b674cba 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx.cs @@ -22,7 +22,41 @@ namespace umbraco.presentation.webservices /// [WebService(Namespace="http://umbraco.org/webservices/")] public class CacheRefresher : WebService - { + { + + /// + /// This checks the passed in hash and verifies if it does not match the hash of the combination of appDomainAppId and machineName + /// passed in. If the hashes don't match, then cache refreshing continues. + /// + /// + /// + /// + /// + internal bool ContinueRefreshingForRequest(string hash, string appDomainAppId, string machineName) + { + //check if this is the same app id as the one passed in, if it is, then we will ignore + // the request - we will have to assume that the cache refreshing has already been applied to the server + // that executed the request. + if (hash.IsNullOrWhiteSpace() == false && SystemUtilities.GetCurrentTrustLevel() == AspNetHostingPermissionLevel.Unrestricted) + { + var hashedAppId = (machineName + appDomainAppId).ToMd5(); + + //we can only check this in full trust. if it's in medium trust we'll just end up with + // the server refreshing it's cache twice. + if (hashedAppId == hash) + { + LogHelper.Debug( + "The passed in hashed appId equals the current server's hashed appId, cache refreshing will be ignored for this request as it will have already executed for this server (server: {0} , appId: {1} , hash: {2})", + () => machineName, + () => appDomainAppId, + () => hashedAppId); + + return false; + } + } + + return true; + } [WebMethod] public void BulkRefresh(RefreshInstruction[] instructions, string appId, string login, string password) @@ -32,26 +66,7 @@ namespace umbraco.presentation.webservices return; } - //check if this is the same app id as the one passed in, if it is, then we will ignore - // the request - we will have to assume that the cache refeshing has already been applied to the server - // that executed the request. - if (appId.IsNullOrWhiteSpace() == false && SystemUtilities.GetCurrentTrustLevel() == AspNetHostingPermissionLevel.Unrestricted) - { - var hashedAppId = (NetworkHelper.MachineName + HttpRuntime.AppDomainAppId).ToMd5(); - - //we can only check this in full trust. if it's in medium trust we'll just end up with - // the server refreshing it's cache twice. - if (hashedAppId == appId) - { - LogHelper.Debug( - "The passed in hashed appId equals the current server's hashed appId, cache refreshing will be ignored for this request as it will have already executed for this server (server: {0} , appId: {1} , hash: {2})", - () => NetworkHelper.MachineName, - () => HttpRuntime.AppDomainAppId, - () => hashedAppId); - - return; - } - } + if (ContinueRefreshingForRequest(appId, HttpRuntime.AppDomainAppId, NetworkHelper.MachineName) == false) return; //only execute distinct instructions - no sense in running the same one. foreach (var instruction in instructions.Distinct())