diff --git a/Directory.Packages.props b/Directory.Packages.props index 0817e00c6a..48cae8dc62 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -45,8 +45,8 @@ - - + + @@ -100,4 +100,4 @@ - \ No newline at end of file + diff --git a/src/Umbraco.Core/Cache/CacheKeys.cs b/src/Umbraco.Core/Cache/CacheKeys.cs index 7f8484fca4..0e75b6820d 100644 --- a/src/Umbraco.Core/Cache/CacheKeys.cs +++ b/src/Umbraco.Core/Cache/CacheKeys.cs @@ -22,4 +22,6 @@ public static class CacheKeys public const string PreviewPropertyCacheKeyPrefix = "Cache.Property.CacheValues[D:"; public const string PropertyCacheKeyPrefix = "Cache.Property.CacheValues[P:"; + + public const string MemberUserNameCachePrefix = "uRepo_userNameKey+"; } diff --git a/src/Umbraco.Core/Cache/Refreshers/Implement/MemberCacheRefresher.cs b/src/Umbraco.Core/Cache/Refreshers/Implement/MemberCacheRefresher.cs index 18809a6bbe..1c19f62576 100644 --- a/src/Umbraco.Core/Cache/Refreshers/Implement/MemberCacheRefresher.cs +++ b/src/Umbraco.Core/Cache/Refreshers/Implement/MemberCacheRefresher.cs @@ -71,11 +71,22 @@ public sealed class MemberCacheRefresher : PayloadCacheRefresherBase(p.Id)); - memberCache.Result?.Clear(RepositoryCacheKeys.GetKey(p.Username)); + continue; } + + memberCache.Result?.Clear(RepositoryCacheKeys.GetKey(p.Id)); + memberCache.Result?.Clear(RepositoryCacheKeys.GetKey(p.Username)); + + // This specific cache key was introduced to fix an issue where the member username could not be the same as the member id, because the cache keys collided. + // This is done in a bit of a hacky way, because the cache key is created internally in the repository, but we need to clear it here. + // Ideally, we want to use a shared way of generating the key between this and the repository. + // Additionally, the RepositoryCacheKeys actually caches the string to avoid re-allocating memory; we would like to also use this in the repository + // See: + // https://github.com/umbraco/Umbraco-CMS/pull/17350 + // https://github.com/umbraco/Umbraco-CMS/pull/17815 + memberCache.Result?.Clear(RepositoryCacheKeys.GetKey(CacheKeys.MemberUserNameCachePrefix + p.Username)); } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs index 75ea4f365d..9adc60426f 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs @@ -39,7 +39,6 @@ public class MemberRepository : ContentRepositoryBase - _memberByUsernameCachePolicy.GetByUserName(UsernameCacheKey, username, PerformGetByUsername, PerformGetAllByUsername); + _memberByUsernameCachePolicy.GetByUserName(CacheKeys.MemberUserNameCachePrefix, username, PerformGetByUsername, PerformGetAllByUsername); public int[] GetMemberIds(string[] usernames) { @@ -609,7 +608,7 @@ public class MemberRepository : ContentRepositoryBase