diff --git a/src/Umbraco.Core/Cache/CacheRefresherBase.cs b/src/Umbraco.Core/Cache/CacheRefresherBase.cs index d69f2daebc..e9b63976d2 100644 --- a/src/Umbraco.Core/Cache/CacheRefresherBase.cs +++ b/src/Umbraco.Core/Cache/CacheRefresherBase.cs @@ -13,6 +13,11 @@ namespace Umbraco.Core.Cache public abstract class CacheRefresherBase : ICacheRefresher where TInstanceType : ICacheRefresher { + protected CacheRefresherBase(CacheHelper cacheHelper) + { + CacheHelper = cacheHelper; + } + /// /// An event that is raised when cache is updated on an individual server /// @@ -44,6 +49,8 @@ namespace Umbraco.Core.Cache public abstract string Name { get; } + protected CacheHelper CacheHelper { get; } + public virtual void RefreshAll() { OnCacheUpdated(Instance, new CacheRefresherEventArgs(null, MessageType.RefreshAll)); @@ -71,7 +78,7 @@ namespace Umbraco.Core.Cache internal void ClearAllIsolatedCacheByEntityType() where TEntity : class, IAggregateRoot { - ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.ClearCache(); + CacheHelper.IsolatedRuntimeCache.ClearCache(); } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Cache/JsonCacheRefresherBase.cs b/src/Umbraco.Core/Cache/JsonCacheRefresherBase.cs index 1a4133f1c9..ff4276e158 100644 --- a/src/Umbraco.Core/Cache/JsonCacheRefresherBase.cs +++ b/src/Umbraco.Core/Cache/JsonCacheRefresherBase.cs @@ -9,10 +9,16 @@ namespace Umbraco.Core.Cache /// Ensures that the correct events are raised when cache refreshing occurs. public abstract class JsonCacheRefresherBase : CacheRefresherBase, IJsonCacheRefresher where TInstance : ICacheRefresher - { + { + protected JsonCacheRefresherBase(CacheHelper cacheHelper) : base(cacheHelper) + { + } + public virtual void Refresh(string json) { OnCacheUpdated(Instance, new CacheRefresherEventArgs(json, MessageType.RefreshByJson)); } + + } } \ No newline at end of file diff --git a/src/Umbraco.Core/Cache/PayloadCacheRefresherBase.cs b/src/Umbraco.Core/Cache/PayloadCacheRefresherBase.cs index 2bdf80bcc0..b34d49b729 100644 --- a/src/Umbraco.Core/Cache/PayloadCacheRefresherBase.cs +++ b/src/Umbraco.Core/Cache/PayloadCacheRefresherBase.cs @@ -10,6 +10,10 @@ namespace Umbraco.Core.Cache public abstract class PayloadCacheRefresherBase : JsonCacheRefresherBase, IPayloadCacheRefresher where TInstance : ICacheRefresher { + protected PayloadCacheRefresherBase(CacheHelper cacheHelper) : base(cacheHelper) + { + } + protected abstract object Deserialize(string json); public override void Refresh(string json) diff --git a/src/Umbraco.Core/Cache/TypedCacheRefresherBase.cs b/src/Umbraco.Core/Cache/TypedCacheRefresherBase.cs index 5ad914bf27..36b7cdcd0e 100644 --- a/src/Umbraco.Core/Cache/TypedCacheRefresherBase.cs +++ b/src/Umbraco.Core/Cache/TypedCacheRefresherBase.cs @@ -11,6 +11,10 @@ namespace Umbraco.Core.Cache public abstract class TypedCacheRefresherBase : CacheRefresherBase, ICacheRefresher where TInstanceType : ICacheRefresher { + protected TypedCacheRefresherBase(CacheHelper cacheHelper) : base(cacheHelper) + { + } + public virtual void Refresh(TEntityType instance) { OnCacheUpdated(Instance, new CacheRefresherEventArgs(instance, MessageType.RefreshByInstance)); diff --git a/src/Umbraco.Web/Cache/ApplicationCacheRefresher.cs b/src/Umbraco.Web/Cache/ApplicationCacheRefresher.cs index 5c1ec9e1d4..64cd9f0c8d 100644 --- a/src/Umbraco.Web/Cache/ApplicationCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/ApplicationCacheRefresher.cs @@ -9,6 +9,11 @@ namespace Umbraco.Web.Cache /// public sealed class ApplicationCacheRefresher : CacheRefresherBase { + + public ApplicationCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } + protected override ApplicationCacheRefresher Instance { get { return this; } @@ -26,7 +31,7 @@ namespace Umbraco.Web.Cache public override void RefreshAll() { - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(CacheKeys.ApplicationsCacheKey); + CacheHelper.RuntimeCache.ClearCacheItem(CacheKeys.ApplicationsCacheKey); base.RefreshAll(); } @@ -38,7 +43,7 @@ namespace Umbraco.Web.Cache public override void Remove(int id) { - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(CacheKeys.ApplicationsCacheKey); + CacheHelper.RuntimeCache.ClearCacheItem(CacheKeys.ApplicationsCacheKey); base.Remove(id); } diff --git a/src/Umbraco.Web/Cache/ApplicationTreeCacheRefresher.cs b/src/Umbraco.Web/Cache/ApplicationTreeCacheRefresher.cs index 2f1ab4b891..dcee37c271 100644 --- a/src/Umbraco.Web/Cache/ApplicationTreeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/ApplicationTreeCacheRefresher.cs @@ -9,6 +9,11 @@ namespace Umbraco.Web.Cache /// public sealed class ApplicationTreeCacheRefresher : CacheRefresherBase { + + public ApplicationTreeCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } + protected override ApplicationTreeCacheRefresher Instance { get { return this; } @@ -26,7 +31,7 @@ namespace Umbraco.Web.Cache public override void RefreshAll() { - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(CacheKeys.ApplicationTreeCacheKey); + CacheHelper.RuntimeCache.ClearCacheItem(CacheKeys.ApplicationTreeCacheKey); base.RefreshAll(); } @@ -38,7 +43,7 @@ namespace Umbraco.Web.Cache public override void Remove(int id) { - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(CacheKeys.ApplicationTreeCacheKey); + CacheHelper.RuntimeCache.ClearCacheItem(CacheKeys.ApplicationTreeCacheKey); base.Remove(id); } diff --git a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs index 73b254b594..aac3b87746 100644 --- a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs @@ -21,7 +21,7 @@ namespace Umbraco.Web.Cache { private readonly ApplicationContext _applicationContext; - public ContentTypeCacheRefresher(ApplicationContext applicationContext) + public ContentTypeCacheRefresher(ApplicationContext applicationContext) : base(applicationContext.ApplicationCache) { _applicationContext = applicationContext; } diff --git a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs index 11b3ab6294..f11abdf862 100644 --- a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs @@ -15,6 +15,10 @@ namespace Umbraco.Web.Cache public sealed class DataTypeCacheRefresher : JsonCacheRefresherBase { + public DataTypeCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } + #region Static helpers /// @@ -98,13 +102,13 @@ namespace Umbraco.Web.Cache ClearAllIsolatedCacheByEntityType(); ClearAllIsolatedCacheByEntityType(); ClearAllIsolatedCacheByEntityType(); - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(CacheKeys.IdToKeyCacheKey); - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(CacheKeys.KeyToIdCacheKey); + CacheHelper.RuntimeCache.ClearCacheByKeySearch(CacheKeys.IdToKeyCacheKey); + CacheHelper.RuntimeCache.ClearCacheByKeySearch(CacheKeys.KeyToIdCacheKey); payloads.ForEach(payload => { //clears the prevalue cache - var dataTypeCache = ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); + var dataTypeCache = CacheHelper.IsolatedRuntimeCache.GetCache(); if (dataTypeCache) dataTypeCache.Result.ClearCacheByKeySearch(string.Format("{0}{1}", CacheKeys.DataTypePreValuesCacheKey, payload.Id)); diff --git a/src/Umbraco.Web/Cache/DictionaryCacheRefresher.cs b/src/Umbraco.Web/Cache/DictionaryCacheRefresher.cs index ae36be33df..cb4a0f8be0 100644 --- a/src/Umbraco.Web/Cache/DictionaryCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/DictionaryCacheRefresher.cs @@ -11,6 +11,10 @@ namespace Umbraco.Web.Cache /// public sealed class DictionaryCacheRefresher : CacheRefresherBase { + public DictionaryCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } + protected override DictionaryCacheRefresher Instance { get { return this; } diff --git a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs index 4182e0784b..6c8a1ca611 100644 --- a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs +++ b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs @@ -445,10 +445,10 @@ namespace Umbraco.Web.Cache #region Xslt Cache - public static void ClearXsltCacheOnCurrentServer(this DistributedCache dc) + public static void ClearXsltCacheOnCurrentServer(this DistributedCache dc, CacheHelper cacheHelper) { if (UmbracoConfig.For.UmbracoSettings().Content.UmbracoLibraryCacheDuration <= 0) return; - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheObjectTypes("MS.Internal.Xml.XPath.XPathSelectionIterator"); + cacheHelper.RuntimeCache.ClearCacheObjectTypes("MS.Internal.Xml.XPath.XPathSelectionIterator"); } #endregion diff --git a/src/Umbraco.Web/Cache/DomainCacheRefresher.cs b/src/Umbraco.Web/Cache/DomainCacheRefresher.cs index d19d4f6ea0..1c54976b1d 100644 --- a/src/Umbraco.Web/Cache/DomainCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/DomainCacheRefresher.cs @@ -13,6 +13,10 @@ namespace Umbraco.Web.Cache /// public sealed class DomainCacheRefresher : CacheRefresherBase { + public DomainCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } + protected override DomainCacheRefresher Instance { get { return this; } @@ -50,8 +54,10 @@ namespace Umbraco.Web.Cache { ClearAllIsolatedCacheByEntityType(); - // SD: we need to clear the routes cache here! + //TODO: Fix this - if we keep this logic here to clear this cache, then we'll need to use IUmbracoContextAccessor since + // instances of the cache refreshers are singletons, not transient // + // SD: we need to clear the routes cache here! // zpqrtbnk: no, not here, in fact the caches should subsribe to refresh events else we // are creating a nasty dependency - but keep it like that for the time being while // SD is cleaning cache refreshers up. diff --git a/src/Umbraco.Web/Cache/LanguageCacheRefresher.cs b/src/Umbraco.Web/Cache/LanguageCacheRefresher.cs index 087aa36764..e4b6378c8d 100644 --- a/src/Umbraco.Web/Cache/LanguageCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/LanguageCacheRefresher.cs @@ -11,6 +11,10 @@ namespace Umbraco.Web.Cache /// public sealed class LanguageCacheRefresher : CacheRefresherBase { + public LanguageCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } + protected override LanguageCacheRefresher Instance { get { return this; } diff --git a/src/Umbraco.Web/Cache/MacroCacheRefresher.cs b/src/Umbraco.Web/Cache/MacroCacheRefresher.cs index f97ad54e73..34cb397003 100644 --- a/src/Umbraco.Web/Cache/MacroCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/MacroCacheRefresher.cs @@ -19,6 +19,10 @@ namespace Umbraco.Web.Cache /// public class MacroCacheRefresher : JsonCacheRefresherBase { + public MacroCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } + #region Static helpers internal static string[] GetAllMacroCacheKeys() @@ -170,10 +174,10 @@ namespace Umbraco.Web.Cache public override void RefreshAll() { - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheObjectTypes(); + CacheHelper.RuntimeCache.ClearCacheObjectTypes(); GetAllMacroCacheKeys().ForEach( prefix => - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(prefix)); + CacheHelper.RuntimeCache.ClearCacheByKeySearch(prefix)); ClearAllIsolatedCacheByEntityType(); @@ -188,9 +192,9 @@ namespace Umbraco.Web.Cache { GetCacheKeysForAlias(payload.Alias).ForEach( alias => - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(alias)); + CacheHelper.RuntimeCache.ClearCacheByKeySearch(alias)); - var macroRepoCache = ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); + var macroRepoCache = CacheHelper.IsolatedRuntimeCache.GetCache(); if (macroRepoCache) { macroRepoCache.Result.ClearCacheItem(RepositoryBase.GetCacheIdKey(payload.Id)); diff --git a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs b/src/Umbraco.Web/Cache/MediaCacheRefresher.cs index eb33a2f0d8..3abcfb2d0f 100644 --- a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/MediaCacheRefresher.cs @@ -10,6 +10,7 @@ using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories; using System.Linq; +using Umbraco.Core.Services; using Umbraco.Web.PublishedCache.XmlPublishedCache; namespace Umbraco.Web.Cache @@ -22,6 +23,13 @@ namespace Umbraco.Web.Cache /// public class MediaCacheRefresher : JsonCacheRefresherBase { + private readonly IMediaService _mediaService; + + public MediaCacheRefresher(CacheHelper cacheHelper, IMediaService mediaService) : base(cacheHelper) + { + _mediaService = mediaService; + } + #region Static helpers /// @@ -137,34 +145,34 @@ namespace Umbraco.Web.Cache public override void Refresh(int id) { - ClearCache(FromMedia(ApplicationContext.Current.Services.MediaService.GetById(id), OperationType.Saved)); + ClearCache(FromMedia(_mediaService.GetById(id), OperationType.Saved)); base.Refresh(id); } public override void Remove(int id) { - ClearCache(FromMedia(ApplicationContext.Current.Services.MediaService.GetById(id), + ClearCache(FromMedia(_mediaService.GetById(id), //NOTE: we'll just default to trashed for this one. OperationType.Trashed)); base.Remove(id); } - private static void ClearCache(params JsonPayload[] payloads) + private void ClearCache(params JsonPayload[] payloads) { if (payloads == null) return; - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(CacheKeys.IdToKeyCacheKey); - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(CacheKeys.KeyToIdCacheKey); - ApplicationContext.Current.ApplicationCache.ClearPartialViewCache(); + CacheHelper.RuntimeCache.ClearCacheByKeySearch(CacheKeys.IdToKeyCacheKey); + CacheHelper.RuntimeCache.ClearCacheByKeySearch(CacheKeys.KeyToIdCacheKey); + CacheHelper.ClearPartialViewCache(); payloads.ForEach(payload => { - var mediaCache = ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); + var mediaCache = CacheHelper.IsolatedRuntimeCache.GetCache(); //if there's no path, then just use id (this will occur on permanent deletion like emptying recycle bin) if (payload.Path.IsNullOrWhiteSpace()) { - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch( + CacheHelper.RuntimeCache.ClearCacheByKeySearch( string.Format("{0}_{1}", CacheKeys.MediaCacheKey, payload.Id)); } else @@ -177,12 +185,12 @@ namespace Umbraco.Web.Cache mediaCache.Result.ClearCacheItem(RepositoryBase.GetCacheIdKey(idPartAsInt)); } - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch( + CacheHelper.RuntimeCache.ClearCacheByKeySearch( string.Format("{0}_{1}_True", CacheKeys.MediaCacheKey, idPart)); // Also clear calls that only query this specific item! if (idPart == payload.Id.ToString(CultureInfo.InvariantCulture)) - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch( + CacheHelper.RuntimeCache.ClearCacheByKeySearch( string.Format("{0}_{1}", CacheKeys.MediaCacheKey, payload.Id)); } } diff --git a/src/Umbraco.Web/Cache/MemberCacheRefresher.cs b/src/Umbraco.Web/Cache/MemberCacheRefresher.cs index b25293dfdd..ad491a7c96 100644 --- a/src/Umbraco.Web/Cache/MemberCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/MemberCacheRefresher.cs @@ -17,6 +17,9 @@ namespace Umbraco.Web.Cache /// public class MemberCacheRefresher : TypedCacheRefresherBase { + public MemberCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } protected override MemberCacheRefresher Instance { @@ -59,16 +62,16 @@ namespace Umbraco.Web.Cache private void ClearCache(int id) { - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(CacheKeys.IdToKeyCacheKey); - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(CacheKeys.KeyToIdCacheKey); - ApplicationContext.Current.ApplicationCache.ClearPartialViewCache(); + CacheHelper.RuntimeCache.ClearCacheByKeySearch(CacheKeys.IdToKeyCacheKey); + CacheHelper.RuntimeCache.ClearCacheByKeySearch(CacheKeys.KeyToIdCacheKey); + CacheHelper.ClearPartialViewCache(); - ApplicationContext.Current.ApplicationCache.RuntimeCache. + CacheHelper.RuntimeCache. ClearCacheByKeySearch(string.Format("{0}_{1}", CacheKeys.MemberLibraryCacheKey, id)); - ApplicationContext.Current.ApplicationCache.RuntimeCache. + CacheHelper.RuntimeCache. ClearCacheByKeySearch(string.Format("{0}{1}", CacheKeys.MemberBusinessLogicCacheKey, id)); - var memberCache = ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); + var memberCache = CacheHelper.IsolatedRuntimeCache.GetCache(); if (memberCache) memberCache.Result.ClearCacheItem(RepositoryBase.GetCacheIdKey(id)); } diff --git a/src/Umbraco.Web/Cache/MemberGroupCacheRefresher.cs b/src/Umbraco.Web/Cache/MemberGroupCacheRefresher.cs index dc2ba39b9d..1c20ad3c2b 100644 --- a/src/Umbraco.Web/Cache/MemberGroupCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/MemberGroupCacheRefresher.cs @@ -6,11 +6,19 @@ using Umbraco.Core.Cache; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories; +using Umbraco.Core.Services; namespace Umbraco.Web.Cache { public sealed class MemberGroupCacheRefresher : JsonCacheRefresherBase { + private readonly IMemberGroupService _memberGroupService; + + public MemberGroupCacheRefresher(CacheHelper cacheHelper, IMemberGroupService memberGroupService) : base(cacheHelper) + { + _memberGroupService = memberGroupService; + } + #region Static helpers /// @@ -90,13 +98,13 @@ namespace Umbraco.Web.Cache public override void Refresh(int id) { - ClearCache(FromMemberGroup(ApplicationContext.Current.Services.MemberGroupService.GetById(id))); + ClearCache(FromMemberGroup(_memberGroupService.GetById(id))); base.Refresh(id); } public override void Remove(int id) { - ClearCache(FromMemberGroup(ApplicationContext.Current.Services.MemberGroupService.GetById(id))); + ClearCache(FromMemberGroup(_memberGroupService.GetById(id))); base.Remove(id); } @@ -104,7 +112,7 @@ namespace Umbraco.Web.Cache { if (payloads == null) return; - var memberGroupCache = ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); + var memberGroupCache = CacheHelper.IsolatedRuntimeCache.GetCache(); payloads.ForEach(payload => { if (payload != null && memberGroupCache) diff --git a/src/Umbraco.Web/Cache/PageCacheRefresher.cs b/src/Umbraco.Web/Cache/PageCacheRefresher.cs index 472824eef6..283ed650cc 100644 --- a/src/Umbraco.Web/Cache/PageCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/PageCacheRefresher.cs @@ -17,6 +17,9 @@ namespace Umbraco.Web.Cache /// public class PageCacheRefresher : TypedCacheRefresherBase { + public PageCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } protected override PageCacheRefresher Instance { @@ -59,10 +62,10 @@ namespace Umbraco.Web.Cache /// The id. public override void Refresh(int id) { - ApplicationContext.Current.ApplicationCache.ClearPartialViewCache(); + CacheHelper.ClearPartialViewCache(); content.Instance.UpdateDocumentCache(id); DistributedCache.Instance.ClearAllMacroCacheOnCurrentServer(); - DistributedCache.Instance.ClearXsltCacheOnCurrentServer(); + DistributedCache.Instance.ClearXsltCacheOnCurrentServer(CacheHelper); base.Refresh(id); } @@ -72,30 +75,30 @@ namespace Umbraco.Web.Cache /// The id. public override void Remove(int id) { - ApplicationContext.Current.ApplicationCache.ClearPartialViewCache(); + CacheHelper.ClearPartialViewCache(); content.Instance.ClearDocumentCache(id); DistributedCache.Instance.ClearAllMacroCacheOnCurrentServer(); - DistributedCache.Instance.ClearXsltCacheOnCurrentServer(); + DistributedCache.Instance.ClearXsltCacheOnCurrentServer(CacheHelper); ClearAllIsolatedCacheByEntityType(); base.Remove(id); } public override void Refresh(IContent instance) { - ApplicationContext.Current.ApplicationCache.ClearPartialViewCache(); + CacheHelper.ClearPartialViewCache(); content.Instance.UpdateDocumentCache(new Document(instance)); DistributedCache.Instance.ClearAllMacroCacheOnCurrentServer(); - DistributedCache.Instance.ClearXsltCacheOnCurrentServer(); + DistributedCache.Instance.ClearXsltCacheOnCurrentServer(CacheHelper); ClearAllIsolatedCacheByEntityType(); base.Refresh(instance); } public override void Remove(IContent instance) { - ApplicationContext.Current.ApplicationCache.ClearPartialViewCache(); + CacheHelper.ClearPartialViewCache(); content.Instance.ClearDocumentCache(new Document(instance)); DistributedCache.Instance.ClearAllMacroCacheOnCurrentServer(); - DistributedCache.Instance.ClearXsltCacheOnCurrentServer(); + DistributedCache.Instance.ClearXsltCacheOnCurrentServer(CacheHelper); ClearAllIsolatedCacheByEntityType(); base.Remove(instance); } diff --git a/src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs b/src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs index 922e01e2a2..5f52e702e9 100644 --- a/src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs @@ -10,6 +10,10 @@ namespace Umbraco.Web.Cache { public sealed class PublicAccessCacheRefresher : CacheRefresherBase { + public PublicAccessCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } + protected override PublicAccessCacheRefresher Instance { get { return this; } diff --git a/src/Umbraco.Web/Cache/StylesheetCacheRefresher.cs b/src/Umbraco.Web/Cache/StylesheetCacheRefresher.cs deleted file mode 100644 index 959a937e7b..0000000000 --- a/src/Umbraco.Web/Cache/StylesheetCacheRefresher.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.ComponentModel; -using Umbraco.Core; -using Umbraco.Core.Cache; - -namespace Umbraco.Web.Cache -{ - /// - /// A cache refresher to ensure stylesheet cache is refreshed when stylesheets change - /// - [Obsolete("This is no longer used and will be removed in future versions")] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class StylesheetCacheRefresher : CacheRefresherBase - { - protected override StylesheetCacheRefresher Instance - { - get { return this; } - } - - public override Guid UniqueIdentifier - { - get { return new Guid(DistributedCache.StylesheetCacheRefresherId); } - } - - public override string Name - { - get { return "Stylesheet cache refresher"; } - } - - } -} \ No newline at end of file diff --git a/src/Umbraco.Web/Cache/StylesheetPropertyCacheRefresher.cs b/src/Umbraco.Web/Cache/StylesheetPropertyCacheRefresher.cs deleted file mode 100644 index 5b72e0384b..0000000000 --- a/src/Umbraco.Web/Cache/StylesheetPropertyCacheRefresher.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.ComponentModel; -using Umbraco.Core; -using Umbraco.Core.Cache; - -namespace Umbraco.Web.Cache -{ - /// - /// A cache refresher to ensure stylesheet property cache is refreshed when stylesheet properties change - /// - [Obsolete("This is no longer used and will be removed in future versions")] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class StylesheetPropertyCacheRefresher : CacheRefresherBase - { - protected override StylesheetPropertyCacheRefresher Instance - { - get { return this; } - } - - public override Guid UniqueIdentifier - { - get { return new Guid(DistributedCache.StylesheetPropertyCacheRefresherId); } - } - - public override string Name - { - get { return "Stylesheet property cache refresher"; } - } - - } -} \ No newline at end of file diff --git a/src/Umbraco.Web/Cache/TemplateCacheRefresher.cs b/src/Umbraco.Web/Cache/TemplateCacheRefresher.cs index 02e30f2902..59c4051341 100644 --- a/src/Umbraco.Web/Cache/TemplateCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/TemplateCacheRefresher.cs @@ -16,6 +16,10 @@ namespace Umbraco.Web.Cache /// public class TemplateCacheRefresher : CacheRefresherBase { + public TemplateCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } + protected override TemplateCacheRefresher Instance { get { return this; } @@ -59,9 +63,9 @@ namespace Umbraco.Web.Cache private void RemoveFromCache(int id) { - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(CacheKeys.IdToKeyCacheKey); - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(CacheKeys.KeyToIdCacheKey); - ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem( + CacheHelper.RuntimeCache.ClearCacheByKeySearch(CacheKeys.IdToKeyCacheKey); + CacheHelper.RuntimeCache.ClearCacheByKeySearch(CacheKeys.KeyToIdCacheKey); + CacheHelper.RuntimeCache.ClearCacheItem( string.Format("{0}{1}", CacheKeys.TemplateFrontEndCacheKey, id)); //need to clear the runtime cache for templates diff --git a/src/Umbraco.Web/Cache/UnpublishedPageCacheRefresher.cs b/src/Umbraco.Web/Cache/UnpublishedPageCacheRefresher.cs index beb5b8db7d..04dc8d5942 100644 --- a/src/Umbraco.Web/Cache/UnpublishedPageCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/UnpublishedPageCacheRefresher.cs @@ -16,6 +16,10 @@ namespace Umbraco.Web.Cache /// public sealed class UnpublishedPageCacheRefresher : TypedCacheRefresherBase, IJsonCacheRefresher { + public UnpublishedPageCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } + protected override UnpublishedPageCacheRefresher Instance { get { return this; } @@ -139,7 +143,7 @@ namespace Umbraco.Web.Cache private void ClearRepositoryCacheItemById(int id) { - var contentCache = ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); + var contentCache = CacheHelper.IsolatedRuntimeCache.GetCache(); if (contentCache) { contentCache.Result.ClearCacheItem(RepositoryBase.GetCacheIdKey(id)); diff --git a/src/Umbraco.Web/Cache/UserCacheRefresher.cs b/src/Umbraco.Web/Cache/UserCacheRefresher.cs index 834bdcf765..7e8cdf076e 100644 --- a/src/Umbraco.Web/Cache/UserCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/UserCacheRefresher.cs @@ -12,6 +12,10 @@ namespace Umbraco.Web.Cache /// public sealed class UserCacheRefresher : CacheRefresherBase { + public UserCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } + protected override UserCacheRefresher Instance { get { return this; } @@ -43,7 +47,7 @@ namespace Umbraco.Web.Cache public override void Remove(int id) { - var userCache = ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); + var userCache = CacheHelper.IsolatedRuntimeCache.GetCache(); if (userCache) userCache.Result.ClearCacheItem(RepositoryBase.GetCacheIdKey(id)); @@ -55,7 +59,7 @@ namespace Umbraco.Web.Cache private Attempt UserPermissionsCache { - get { return ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); } + get { return CacheHelper.IsolatedRuntimeCache.GetCache(); } } } diff --git a/src/Umbraco.Web/Cache/UserPermissionsCacheRefresher.cs b/src/Umbraco.Web/Cache/UserPermissionsCacheRefresher.cs index eed29ff764..1c888f8b6b 100644 --- a/src/Umbraco.Web/Cache/UserPermissionsCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/UserPermissionsCacheRefresher.cs @@ -14,6 +14,10 @@ namespace Umbraco.Web.Cache /// public sealed class UserPermissionsCacheRefresher : CacheRefresherBase { + public UserPermissionsCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } + protected override UserPermissionsCacheRefresher Instance { get { return this; } @@ -52,7 +56,7 @@ namespace Umbraco.Web.Cache private Attempt UserPermissionsCache { - get { return ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); } + get { return CacheHelper.IsolatedRuntimeCache.GetCache(); } } } } \ No newline at end of file diff --git a/src/Umbraco.Web/Cache/UserTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/UserTypeCacheRefresher.cs index ca3f93c068..00700d2b50 100644 --- a/src/Umbraco.Web/Cache/UserTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/UserTypeCacheRefresher.cs @@ -12,6 +12,10 @@ namespace Umbraco.Web.Cache /// public sealed class UserTypeCacheRefresher : CacheRefresherBase { + public UserTypeCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper) + { + } + protected override UserTypeCacheRefresher Instance { get { return this; } @@ -35,7 +39,7 @@ namespace Umbraco.Web.Cache public override void Refresh(int id) { - var userTypeCache = ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); + var userTypeCache = CacheHelper.IsolatedRuntimeCache.GetCache(); if (userTypeCache) userTypeCache.Result.ClearCacheItem(RepositoryBase.GetCacheIdKey(id)); base.Refresh(id); @@ -43,7 +47,7 @@ namespace Umbraco.Web.Cache public override void Remove(int id) { - var userTypeCache = ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); + var userTypeCache = CacheHelper.IsolatedRuntimeCache.GetCache(); if (userTypeCache) userTypeCache.Result.ClearCacheItem(RepositoryBase.GetCacheIdKey(id)); base.Remove(id); diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index afa98a407b..0093389468 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -479,8 +479,6 @@ - -