From 6719d70cc061727575b254b9cb2f23bb9bf4fd64 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 28 Jan 2014 09:22:01 +1100 Subject: [PATCH] Updates UserTypeCacheRefresher to clear the runtime cache accordingly. --- src/Umbraco.Core/Cache/CacheKeys.cs | 3 +++ .../Cache/CacheRefresherEventHandler.cs | 21 +++++++------------ .../Cache/UserTypeCacheRefresher.cs | 8 ++++--- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Umbraco.Core/Cache/CacheKeys.cs b/src/Umbraco.Core/Cache/CacheKeys.cs index fc17bd7245..338ea3a70e 100644 --- a/src/Umbraco.Core/Cache/CacheKeys.cs +++ b/src/Umbraco.Core/Cache/CacheKeys.cs @@ -1,3 +1,5 @@ +using System; + namespace Umbraco.Core.Cache { @@ -9,6 +11,7 @@ namespace Umbraco.Core.Cache public const string ApplicationTreeCacheKey = "ApplicationTreeCache"; public const string ApplicationsCacheKey = "ApplicationCache"; + [Obsolete("This is no longer used and will be removed from the codebase in the future")] public const string UserTypeCacheKey = "UserTypeCache"; public const string ContentItemCacheKey = "contentItem"; diff --git a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs index 818c5f5d58..3b76060b9a 100644 --- a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs +++ b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs @@ -34,9 +34,8 @@ namespace Umbraco.Web.Cache Application.New += ApplicationNew; //bind to user type events - UserType.Deleted += UserTypeDeleted; - UserType.New += UserTypeNew; - UserType.Updated += UserTypeUpdated; + UserService.SavedUserType += UserServiceSavedUserType; + UserService.DeletedUserType += UserServiceDeletedUserType; //Bind to dictionary events //NOTE: we need to bind to legacy and new API events currently: http://issues.umbraco.org/issue/U4-1979 @@ -131,9 +130,7 @@ namespace Umbraco.Web.Cache ContentService.Created += ContentServiceCreated; ContentService.Copied += ContentServiceCopied; } - - #region Content service event handlers /// @@ -199,20 +196,16 @@ namespace Umbraco.Web.Cache #endregion #region UserType event handlers - static void UserTypeUpdated(UserType sender, System.EventArgs e) + static void UserServiceDeletedUserType(IUserService sender, Core.Events.DeleteEventArgs e) { - DistributedCache.Instance.RefreshUserTypeCache(sender.Id); + e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveUserTypeCache(x.Id)); } - static void UserTypeNew(UserType sender, System.EventArgs e) + static void UserServiceSavedUserType(IUserService sender, Core.Events.SaveEventArgs e) { - DistributedCache.Instance.RefreshAllUserTypeCache(); + e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshUserTypeCache(x.Id)); } - - static void UserTypeDeleted(UserType sender, System.EventArgs e) - { - DistributedCache.Instance.RemoveUserTypeCache(sender.Id); - } + #endregion #region Dictionary event handlers diff --git a/src/Umbraco.Web/Cache/UserTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/UserTypeCacheRefresher.cs index d4ec8a0d60..7c4628dbe3 100644 --- a/src/Umbraco.Web/Cache/UserTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/UserTypeCacheRefresher.cs @@ -1,6 +1,8 @@ using System; using Umbraco.Core; using Umbraco.Core.Cache; +using Umbraco.Core.Models.Membership; +using Umbraco.Core.Persistence.Caching; namespace Umbraco.Web.Cache { @@ -26,17 +28,17 @@ namespace Umbraco.Web.Cache public override void RefreshAll() { - ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(CacheKeys.UserTypeCacheKey); + RuntimeCacheProvider.Current.Clear(typeof (IUserType)); } public override void Refresh(int id) { - Remove(id); + RuntimeCacheProvider.Current.Delete(typeof(IUserType), id); } public override void Remove(int id) { - ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(CacheKeys.UserTypeCacheKey); + RuntimeCacheProvider.Current.Delete(typeof(IUserType), id); } }