2021-03-15 13:39:34 +11:00
|
|
|
using System;
|
2021-03-12 21:48:24 +01:00
|
|
|
using Umbraco.Cms.Core.Events;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Models.Membership;
|
2021-05-11 14:33:49 +02:00
|
|
|
using Umbraco.Cms.Core.Notifications;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Persistence.Repositories;
|
2017-09-08 19:39:13 +02:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Core.Cache
|
2017-09-08 19:39:13 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles User group cache invalidation/refreshing
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This also needs to clear the user cache since IReadOnlyUserGroup's are attached to IUser objects
|
|
|
|
|
/// </remarks>
|
2021-03-12 21:48:24 +01:00
|
|
|
public sealed class UserGroupCacheRefresher : CacheRefresherBase<UserGroupCacheRefresherNotification>
|
2017-09-08 19:39:13 +02:00
|
|
|
{
|
2021-03-15 13:39:34 +11:00
|
|
|
public UserGroupCacheRefresher(AppCaches appCaches, IEventAggregator eventAggregator, ICacheRefresherNotificationFactory factory)
|
|
|
|
|
: base(appCaches, eventAggregator, factory)
|
2017-09-08 19:39:13 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
#region Define
|
|
|
|
|
|
|
|
|
|
public static readonly Guid UniqueId = Guid.Parse("45178038-B232-4FE8-AA1A-F2B949C44762");
|
|
|
|
|
|
|
|
|
|
public override Guid RefresherUniqueId => UniqueId;
|
|
|
|
|
|
|
|
|
|
public override string Name => "User Group Cache Refresher";
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Refresher
|
|
|
|
|
|
|
|
|
|
public override void RefreshAll()
|
|
|
|
|
{
|
|
|
|
|
ClearAllIsolatedCacheByEntityType<IUserGroup>();
|
2019-01-17 11:01:23 +01:00
|
|
|
var userGroupCache = AppCaches.IsolatedCaches.Get<IUserGroup>();
|
2022-02-09 13:24:35 +01:00
|
|
|
if (userGroupCache.Success)
|
2017-09-08 19:39:13 +02:00
|
|
|
{
|
2022-01-13 09:27:37 +01:00
|
|
|
userGroupCache.Result?.ClearByKey(CacheKeys.UserGroupGetByAliasCacheKeyPrefix);
|
2017-09-08 19:39:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//We'll need to clear all user cache too
|
|
|
|
|
ClearAllIsolatedCacheByEntityType<IUser>();
|
|
|
|
|
|
|
|
|
|
base.RefreshAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Refresh(int id)
|
|
|
|
|
{
|
|
|
|
|
Remove(id);
|
|
|
|
|
base.Refresh(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Remove(int id)
|
|
|
|
|
{
|
2019-01-17 11:01:23 +01:00
|
|
|
var userGroupCache = AppCaches.IsolatedCaches.Get<IUserGroup>();
|
2022-02-09 13:24:35 +01:00
|
|
|
if (userGroupCache.Success)
|
2017-09-08 19:39:13 +02:00
|
|
|
{
|
2022-01-13 09:27:37 +01:00
|
|
|
userGroupCache.Result?.Clear(RepositoryCacheKeys.GetKey<IUserGroup, int>(id));
|
|
|
|
|
userGroupCache.Result?.ClearByKey(CacheKeys.UserGroupGetByAliasCacheKeyPrefix);
|
2017-09-08 19:39:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//we don't know what user's belong to this group without doing a look up so we'll need to just clear them all
|
|
|
|
|
ClearAllIsolatedCacheByEntityType<IUser>();
|
|
|
|
|
|
|
|
|
|
base.Remove(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
2017-09-23 10:08:18 +02:00
|
|
|
}
|