From d451390d781b4566519e8f55c6ab2d3fc5c0014b Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Mon, 16 Dec 2024 07:18:30 +0100 Subject: [PATCH] V13: Clear username cache (#17815) * Clear member username cache on delete * Also refresh cache on update --- .../Cache/MemberRepositoryUsernameCachePolicy.cs | 6 ++++++ .../Repositories/Implement/MemberRepository.cs | 11 ++++++++++- 2 files changed, 16 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 1f7c5519d585..75ea4f365d88 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs @@ -39,6 +39,7 @@ public class MemberRepository : ContentRepositoryBase GetPage( } public IMember? GetByUsername(string? username) => - _memberByUsernameCachePolicy.GetByUserName("uRepo_userNameKey+", username, PerformGetByUsername, PerformGetAllByUsername); + _memberByUsernameCachePolicy.GetByUserName(UsernameCacheKey, username, PerformGetByUsername, PerformGetAllByUsername); public int[] GetMemberIds(string[] usernames) { @@ -606,6 +607,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); @@ -936,6 +943,8 @@ protected override void PersistUpdatedItem(IMember entity) OnUowRefreshedEntity(new MemberRefreshNotification(entity, new EventMessages())); + _memberByUsernameCachePolicy.DeleteByUserName(UsernameCacheKey, entity.Username); + entity.ResetDirtyProperties(); }