Fixes: #U4-2041, #U4-2040 - user cache is not invalidated when permissions change across LB environments, also streamlined how caching is handled in
these classes which now use the standardized events way to do things. Fixes a performance issue and ensures that the cache is not invalidated for 'micro' operations during permission changes.
This commit is contained in:
@@ -77,6 +77,12 @@ namespace Umbraco.Web.Cache
|
||||
User.Saving += UserSaving;
|
||||
User.Deleting += UserDeleting;
|
||||
|
||||
//Bind to permission events
|
||||
|
||||
Permission.New += PermissionNew;
|
||||
Permission.Updated += PermissionUpdated;
|
||||
Permission.Deleted += PermissionDeleted;
|
||||
|
||||
//Bind to template events
|
||||
//NOTE: we need to bind to legacy and new API events currently: http://issues.umbraco.org/issue/U4-1979
|
||||
|
||||
@@ -105,7 +111,7 @@ namespace Umbraco.Web.Cache
|
||||
MediaService.Moving += MediaServiceMoving;
|
||||
MediaService.Trashing += MediaServiceTrashing;
|
||||
}
|
||||
|
||||
|
||||
#region Dictionary event handlers
|
||||
|
||||
static void LocalizationServiceSavedDictionaryItem(ILocalizationService sender, Core.Events.SaveEventArgs<IDictionaryItem> e)
|
||||
@@ -301,6 +307,22 @@ namespace Umbraco.Web.Cache
|
||||
#endregion
|
||||
|
||||
#region User event handlers
|
||||
|
||||
static void PermissionDeleted(UserPermission sender, DeleteEventArgs e)
|
||||
{
|
||||
InvalidateCacheForPermissionsChange(sender);
|
||||
}
|
||||
|
||||
static void PermissionUpdated(UserPermission sender, SaveEventArgs e)
|
||||
{
|
||||
InvalidateCacheForPermissionsChange(sender);
|
||||
}
|
||||
|
||||
static void PermissionNew(UserPermission sender, NewEventArgs e)
|
||||
{
|
||||
InvalidateCacheForPermissionsChange(sender);
|
||||
}
|
||||
|
||||
static void UserDeleting(User sender, System.EventArgs e)
|
||||
{
|
||||
DistributedCache.Instance.RemoveUserCache(sender.Id);
|
||||
@@ -309,7 +331,24 @@ namespace Umbraco.Web.Cache
|
||||
static void UserSaving(User sender, System.EventArgs e)
|
||||
{
|
||||
DistributedCache.Instance.RefreshUserCache(sender.Id);
|
||||
}
|
||||
}
|
||||
|
||||
private static void InvalidateCacheForPermissionsChange(UserPermission sender)
|
||||
{
|
||||
if (sender.User != null)
|
||||
{
|
||||
DistributedCache.Instance.RefreshUserCache(sender.User.Id);
|
||||
}
|
||||
if (sender.UserId > -1)
|
||||
{
|
||||
DistributedCache.Instance.RefreshUserCache(sender.UserId);
|
||||
}
|
||||
if (sender.Nodes.Any())
|
||||
{
|
||||
DistributedCache.Instance.RefreshAllUserCache();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Template event handlers
|
||||
|
||||
@@ -22,6 +22,11 @@ namespace Umbraco.Web.Cache
|
||||
public static void RefreshUserCache(this DistributedCache dc, int userId)
|
||||
{
|
||||
dc.Refresh(new Guid(DistributedCache.UserCacheRefresherId), userId);
|
||||
}
|
||||
|
||||
public static void RefreshAllUserCache(this DistributedCache dc)
|
||||
{
|
||||
dc.RefreshAll(new Guid(DistributedCache.UserCacheRefresherId));
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user