diff --git a/src/Umbraco.Infrastructure/Cache/MemberRepositoryUsernameCachePolicy.cs b/src/Umbraco.Infrastructure/Cache/MemberRepositoryUsernameCachePolicy.cs index 1dc5f42a0117..807c3d2d2c40 100644 --- a/src/Umbraco.Infrastructure/Cache/MemberRepositoryUsernameCachePolicy.cs +++ b/src/Umbraco.Infrastructure/Cache/MemberRepositoryUsernameCachePolicy.cs @@ -30,4 +30,10 @@ public MemberRepositoryUsernameCachePolicy(IAppPolicyCache cache, IScopeAccessor return entity; } + + public void DeleteByUserName(string key, string? username) + { + var cacheKey = GetEntityCacheKey(key + username); + Cache.ClearByKey(cacheKey); + } } diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs index 053cb15b2d08..0815595c0695 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs @@ -38,6 +38,7 @@ public class MemberRepository : ContentRepositoryBase GetPage(IQuery? query, } public IMember? GetByUsername(string? username) => - _memberByUsernameCachePolicy.GetByUserName("uRepo_userNameKey+", username, PerformGetByUsername, PerformGetAllByUsername); + _memberByUsernameCachePolicy.GetByUserName(UsernameCacheKey, username, PerformGetByUsername, PerformGetAllByUsername); public int[] GetMemberIds(string[] usernames) { @@ -508,6 +509,12 @@ protected virtual Sql GetBaseQuery(QueryType queryType, bool curren return sql; } + protected override void PersistDeletedItem(IMember entity) + { + _memberByUsernameCachePolicy.DeleteByUserName(UsernameCacheKey, entity.Username); + base.PersistDeletedItem(entity); + } + // TODO: move that one up to Versionable! or better: kill it! protected override Sql GetBaseQuery(bool isCount) => GetBaseQuery(isCount ? QueryType.Count : QueryType.Single); @@ -837,6 +844,8 @@ protected override void PersistUpdatedItem(IMember entity) OnUowRefreshedEntity(new MemberRefreshNotification(entity, new EventMessages())); + _memberByUsernameCachePolicy.DeleteByUserName(UsernameCacheKey, entity.Username); + entity.ResetDirtyProperties(); }