Support publishing multiple notifications, filter on handler type and add IDistributedCacheNotificationHandler<TNotification> (optimizes cache refreshers) (#14332)
* Clean up DistributedCache and add additional checks * Add IEnumerable overloads to DistributedCacheExtensions * Update handlers to use new IEnumerable overloads * Move DistributedCacheExtensions to Core * Restructure cache refreshers into folders * Add IDistributedCacheNotificationHandler * Rewrite DistributedCacheBinder into seperate IDistributedCacheNotificationHandler implementations * Obsolete DistributedCacheBinder and use new IDistributedCacheHandler implementations * Clean up ServerMessengerBase * Ensure cache refreshers only process distinct values * Add support for publishing multiple notifications and filter on handler type * Suppress compatibility issues * Remove DistributedCacheBinder and suppress compatibility issues * Add ScopedNotificationPublisher<TNotificationHandler> * Improve notification type lookup/enumeration * Ensure INotificationAsyncHandler handles multiple notitications sequentially * Minimize cache instruction JSON * Chunk notifications by type to keep publish order * Only serialize required RefreshInstruction properties
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Models.Membership;
|
||||
using Umbraco.Cms.Core.Notifications;
|
||||
using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
|
||||
namespace Umbraco.Cms.Core.Cache;
|
||||
|
||||
/// <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>
|
||||
public sealed class UserGroupCacheRefresher : CacheRefresherBase<UserGroupCacheRefresherNotification>
|
||||
{
|
||||
#region Define
|
||||
|
||||
public static readonly Guid UniqueId = Guid.Parse("45178038-B232-4FE8-AA1A-F2B949C44762");
|
||||
|
||||
public UserGroupCacheRefresher(AppCaches appCaches, IEventAggregator eventAggregator, ICacheRefresherNotificationFactory factory)
|
||||
: base(appCaches, eventAggregator, factory)
|
||||
{
|
||||
}
|
||||
|
||||
public override Guid RefresherUniqueId => UniqueId;
|
||||
|
||||
public override string Name => "User Group Cache Refresher";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Refresher
|
||||
|
||||
public override void RefreshAll()
|
||||
{
|
||||
ClearAllIsolatedCacheByEntityType<IUserGroup>();
|
||||
Attempt<IAppPolicyCache?> userGroupCache = AppCaches.IsolatedCaches.Get<IUserGroup>();
|
||||
if (userGroupCache.Success)
|
||||
{
|
||||
userGroupCache.Result?.ClearByKey(CacheKeys.UserGroupGetByAliasCacheKeyPrefix);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
Attempt<IAppPolicyCache?> userGroupCache = AppCaches.IsolatedCaches.Get<IUserGroup>();
|
||||
if (userGroupCache.Success)
|
||||
{
|
||||
userGroupCache.Result?.Clear(RepositoryCacheKeys.GetKey<IUserGroup, int>(id));
|
||||
userGroupCache.Result?.ClearByKey(CacheKeys.UserGroupGetByAliasCacheKeyPrefix);
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user