From b4daab2856af05b8d3b10578a548593dc10c1fcd Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 27 Mar 2014 14:28:45 +1100 Subject: [PATCH] started fixing: U4-459 Public Access permissions not set on distributed servers but have commented that code out for now because it will cause problem in some LB scenarios. --- .../Cache/CacheRefresherEventHandler.cs | 18 ++++- src/Umbraco.Web/Cache/DistributedCache.cs | 1 + .../Cache/DistributedCacheExtensions.cs | 11 +++ src/Umbraco.Web/Cache/MediaCacheRefresher.cs | 2 +- .../Cache/PublicAccessCacheRefresher.cs | 81 +++++++++++++++++++ src/Umbraco.Web/Umbraco.Web.csproj | 1 + 6 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs diff --git a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs index 5ad59a14da..6c3ddb8418 100644 --- a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs +++ b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs @@ -142,9 +142,25 @@ namespace Umbraco.Web.Cache //NOTE: we do not listen for the trashed event because there is no cache to update for content in that case since // the unpublishing event handles that, and for examine with unpublished content indexes, we want to keep that data // in the index, it's not until it's complete deleted that we want to remove it. + + //SD: We are not using this, i was going to use this for the PublicAccessCacheRefresher but we need + // to store the public access in the db otherwise we're gonna end up with problems in certain LB + // scenarios + + ////public access events + //Access.AfterSave += Access_AfterSave; } - + //SD: We are not using this, i was going to use this for the PublicAccessCacheRefresher but we need + // to store the public access in the db otherwise we're gonna end up with problems in certain LB + // scenarios + + //#region Public access event handlers + //static void Access_AfterSave(Access sender, SaveEventArgs e) + //{ + // DistributedCache.Instance.RefreshPublicAccess(); + //} + //#endregion #region Content service event handlers diff --git a/src/Umbraco.Web/Cache/DistributedCache.cs b/src/Umbraco.Web/Cache/DistributedCache.cs index b0b6b917e3..24c555b195 100644 --- a/src/Umbraco.Web/Cache/DistributedCache.cs +++ b/src/Umbraco.Web/Cache/DistributedCache.cs @@ -54,6 +54,7 @@ namespace Umbraco.Web.Cache public const string StylesheetPropertyCacheRefresherId = "2BC7A3A4-6EB1-4FBC-BAA3-C9E7B6D36D38"; public const string DataTypeCacheRefresherId = "35B16C25-A17E-45D7-BC8F-EDAB1DCC28D2"; public const string DictionaryCacheRefresherId = "D1D7E227-F817-4816-BFE9-6C39B6152884"; + //public const string PublicAccessCacheRefresherId = "1DB08769-B104-4F8B-850E-169CAC1DF2EC"; #endregion diff --git a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs index 601a189107..8623b0da20 100644 --- a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs +++ b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs @@ -14,6 +14,17 @@ namespace Umbraco.Web.Cache /// internal static class DistributedCacheExtensions { + #region Public access + + public static void RefreshPublicAccess(this DistributedCache dc) + { + dc.RefreshByJson(new Guid(DistributedCache.PublicAccessCacheRefresherId), + PublicAccessCacheRefresher.SerializeToJsonPayload( + Access.AccessXml)); + } + + #endregion + #region Application tree cache public static void RefreshAllApplicationTreeCache(this DistributedCache dc) { diff --git a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs b/src/Umbraco.Web/Cache/MediaCacheRefresher.cs index 72a541b720..a2de17626f 100644 --- a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/MediaCacheRefresher.cs @@ -4,13 +4,13 @@ using System.Globalization; using System.Web.Script.Serialization; using Umbraco.Core; using Umbraco.Core.Cache; +using Umbraco.Core.IO; using Umbraco.Core.Models; using umbraco.interfaces; using System.Linq; namespace Umbraco.Web.Cache { - /// /// A cache refresher to ensure media cache is updated /// diff --git a/src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs b/src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs new file mode 100644 index 0000000000..9d6e2c0c20 --- /dev/null +++ b/src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs @@ -0,0 +1,81 @@ +using System; +using System.Xml; +using Newtonsoft.Json; +using umbraco.cms.businesslogic.web; +using Umbraco.Core; +using Umbraco.Core.Cache; + +namespace Umbraco.Web.Cache +{ + //SD: We are not using this, i was going to use this for the PublicAccessCacheRefresher but we need + // to store the public access in the db otherwise we're gonna end up with problems in certain LB + // scenarios + + //public sealed class PublicAccessCacheRefresher : JsonCacheRefresherBase + //{ + // #region Static helpers + + // internal static JsonPayload DeserializeFromJsonPayload(string json) + // { + // return JsonConvert.DeserializeObject(json); + // } + + // internal static string SerializeToJsonPayload(XmlDocument doc) + // { + // return JsonConvert.SerializeObject(FromXml(doc)); + // } + + // internal static JsonPayload FromXml(XmlDocument doc) + // { + // if (doc == null) return null; + + // var payload = new JsonPayload + // { + // XmlContent = doc.OuterXml + // }; + // return payload; + // } + + // #endregion + + // #region Sub classes + + // internal class JsonPayload + // { + // public string XmlContent { get; set; } + // } + + // #endregion + + // protected override PublicAccessCacheRefresher Instance + // { + // get { return this; } + // } + + // public override Guid UniqueIdentifier + // { + // get { return new Guid(DistributedCache.PublicAccessCacheRefresherId); } + // } + + // public override string Name + // { + // get { return "Public access cache refresher"; } + // } + + // public override void Refresh(string jsonPayload) + // { + // if (jsonPayload.IsNullOrWhiteSpace()) return; + // var deserialized = DeserializeFromJsonPayload(jsonPayload); + // if (deserialized == null) return; + // var xDoc = new XmlDocument(); + // xDoc.LoadXml(deserialized.XmlContent); + // ClearCache(xDoc); + // base.Refresh(jsonPayload); + // } + + // private void ClearCache(XmlDocument xDoc) + // { + // Access.Reload(xDoc); + // } + //} +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index deff943781..29815c85d6 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -286,6 +286,7 @@ +