Files
Umbraco-CMS/src/Umbraco.Core/Cache/UserCacheRefresher.cs

57 lines
1.7 KiB
C#
Raw Normal View History

using System;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Persistence.Repositories;
2018-06-29 19:52:40 +02:00
namespace Umbraco.Cms.Core.Cache
2018-06-29 19:52:40 +02:00
{
public sealed class UserCacheRefresher : CacheRefresherBase<UserCacheRefresherNotification>
2018-06-29 19:52:40 +02:00
{
public UserCacheRefresher(AppCaches appCaches, IEventAggregator eventAggregator, ICacheRefresherNotificationFactory factory)
: base(appCaches, eventAggregator, factory)
2018-06-29 19:52:40 +02:00
{ }
#region Define
public static readonly Guid UniqueId = Guid.Parse("E057AF6D-2EE6-41F4-8045-3694010F0AA6");
public override Guid RefresherUniqueId => UniqueId;
public override string Name => "User Cache Refresher";
#endregion
#region Refresher
public override void RefreshAll()
{
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 userCache = AppCaches.IsolatedCaches.Get<IUser>();
2022-02-09 13:24:35 +01:00
if (userCache.Success)
{
2022-01-13 09:27:37 +01:00
userCache.Result?.Clear(RepositoryCacheKeys.GetKey<IUser, int>(id));
userCache.Result?.ClearByKey(CacheKeys.UserContentStartNodePathsPrefix + id);
userCache.Result?.ClearByKey(CacheKeys.UserMediaStartNodePathsPrefix + id);
userCache.Result?.ClearByKey(CacheKeys.UserAllContentStartNodesPrefix + id);
userCache.Result?.ClearByKey(CacheKeys.UserAllMediaStartNodesPrefix + id);
}
2018-06-29 19:52:40 +02:00
base.Remove(id);
}
#endregion
}
}