From d902127e600a62a2911f8ddc7ddc7e58e991a8e4 Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:21:06 +0100 Subject: [PATCH 1/2] Clear member username cache on delete --- .../Cache/MemberRepositoryUsernameCachePolicy.cs | 6 ++++++ .../Repositories/Implement/MemberRepository.cs | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) 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..ed820d1b8a46 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); From ee0a3320ad623bb63a9eaa65c86ab3a0e4bac815 Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:22:51 +0100 Subject: [PATCH 2/2] Also refresh cache on update --- .../Persistence/Repositories/Implement/MemberRepository.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs index ed820d1b8a46..0815595c0695 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs @@ -844,6 +844,8 @@ protected override void PersistUpdatedItem(IMember entity) OnUowRefreshedEntity(new MemberRefreshNotification(entity, new EventMessages())); + _memberByUsernameCachePolicy.DeleteByUserName(UsernameCacheKey, entity.Username); + entity.ResetDirtyProperties(); }