diff --git a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs index 6c3ddb8418..efecd08552 100644 --- a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs +++ b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs @@ -143,24 +143,18 @@ namespace Umbraco.Web.Cache // 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; + //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 - //#region Public access event handlers - //static void Access_AfterSave(Access sender, SaveEventArgs e) - //{ - // DistributedCache.Instance.RefreshPublicAccess(); - //} - //#endregion + 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 24c555b195..326fbd0239 100644 --- a/src/Umbraco.Web/Cache/DistributedCache.cs +++ b/src/Umbraco.Web/Cache/DistributedCache.cs @@ -54,7 +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"; + public const string PublicAccessCacheRefresherId = "1DB08769-B104-4F8B-850E-169CAC1DF2EC"; #endregion diff --git a/src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs b/src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs index 9d6e2c0c20..0c700e9dfa 100644 --- a/src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs @@ -7,75 +7,71 @@ 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 - //public sealed class PublicAccessCacheRefresher : JsonCacheRefresherBase - //{ - // #region Static helpers + internal static JsonPayload DeserializeFromJsonPayload(string json) + { + return JsonConvert.DeserializeObject(json); + } - // internal static JsonPayload DeserializeFromJsonPayload(string json) - // { - // return JsonConvert.DeserializeObject(json); - // } + internal static string SerializeToJsonPayload(XmlDocument doc) + { + return JsonConvert.SerializeObject(FromXml(doc)); + } - // internal static string SerializeToJsonPayload(XmlDocument doc) - // { - // return JsonConvert.SerializeObject(FromXml(doc)); - // } + internal static JsonPayload FromXml(XmlDocument doc) + { + if (doc == null) return null; - // internal static JsonPayload FromXml(XmlDocument doc) - // { - // if (doc == null) return null; + var payload = new JsonPayload + { + XmlContent = doc.OuterXml + }; + return payload; + } - // var payload = new JsonPayload - // { - // XmlContent = doc.OuterXml - // }; - // return payload; - // } + #endregion - // #endregion + #region Sub classes - // #region Sub classes + internal class JsonPayload + { + public string XmlContent { get; set; } + } - // internal class JsonPayload - // { - // public string XmlContent { get; set; } - // } + #endregion - // #endregion + protected override PublicAccessCacheRefresher Instance + { + get { return this; } + } - // protected override PublicAccessCacheRefresher Instance - // { - // get { return this; } - // } + public override Guid UniqueIdentifier + { + get { return new Guid(DistributedCache.PublicAccessCacheRefresherId); } + } - // public override Guid UniqueIdentifier - // { - // get { return new Guid(DistributedCache.PublicAccessCacheRefresherId); } - // } + public override string Name + { + get { return "Public access cache refresher"; } + } - // 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); + } - // 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); - // } - //} + private void ClearCache(XmlDocument xDoc) + { + Access.UpdateInMemoryDocument(xDoc); + } + } } \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/web/Access.cs b/src/umbraco.cms/businesslogic/web/Access.cs index e9c11351ff..7fbbf58d01 100644 --- a/src/umbraco.cms/businesslogic/web/Access.cs +++ b/src/umbraco.cms/businesslogic/web/Access.cs @@ -95,29 +95,26 @@ namespace umbraco.cms.businesslogic.web new Access().FireAfterAddMemberShipRoleToDocument(new Document(documentId), role, e); } - //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 - - //internal static void Reload(XmlDocument newDoc) - //{ - // //NOTE: This would be better to use our normal ReaderWriter lock but because we are emitting an - // // event inside of the WriteLock and code can then listen to the event and call this method we end - // // up in a dead-lock. This specifically happens in the PublicAccessCacheRefresher. - // //So instead we use the load locker which is what is used for the static XmlDocument instance, we'll - // // lock that, set the doc to null which will cause any reader threads to block for the AccessXml instance - // // then save the doc and re-load it, then all blocked threads can carry on. - // lock(LoadLocker) - // { - // _accessXmlContent = null; - - // newDoc.Save(_accessXmlSource); - - // _accessXmlContent = new XmlDocument(); - // _accessXmlContent.Load(_accessXmlSource); - // ClearCheckPages(); - // } - //} + /// + /// Used to refresh cache among servers in an LB scenario + /// + /// + internal static void UpdateInMemoryDocument(XmlDocument newDoc) + { + //NOTE: This would be better to use our normal ReaderWriter lock but because we are emitting an + // event inside of the WriteLock and code can then listen to the event and call this method we end + // up in a dead-lock. This specifically happens in the PublicAccessCacheRefresher. + //So instead we use the load locker which is what is used for the static XmlDocument instance, we'll + // lock that, set the doc to null which will cause any reader threads to block for the AccessXml instance + // then save the doc and re-load it, then all blocked threads can carry on. + lock (LoadLocker) + { + _accessXmlContent = null; + _accessXmlContent = new XmlDocument(); + _accessXmlContent.LoadXml(newDoc.OuterXml); + ClearCheckPages(); + } + } [Obsolete("This method is no longer supported. Use the ASP.NET MemberShip methods instead", true)] public static void AddMemberGroupToDocument(int DocumentId, int MemberGroupId)