Skip to content

Commit

Permalink
V13: Clear username cache (#17815)
Browse files Browse the repository at this point in the history
* Clear member username cache on delete

* Also refresh cache on update
  • Loading branch information
Zeegaan authored and elit0451 committed Dec 16, 2024
1 parent cb88cbb commit d451390
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class MemberRepository : ContentRepositoryBase<int, IMember, MemberReposi
private readonly ITagRepository _tagRepository;
private bool _passwordConfigInitialized;
private string? _passwordConfigJson;
private const string UsernameCacheKey = "uRepo_userNameKey+";

public MemberRepository(
IScopeAccessor scopeAccessor,
Expand Down Expand Up @@ -326,7 +327,7 @@ public override IEnumerable<IMember> GetPage(
}

public IMember? GetByUsername(string? username) =>
_memberByUsernameCachePolicy.GetByUserName("uRepo_userNameKey+", username, PerformGetByUsername, PerformGetAllByUsername);
_memberByUsernameCachePolicy.GetByUserName(UsernameCacheKey, username, PerformGetByUsername, PerformGetAllByUsername);

public int[] GetMemberIds(string[] usernames)
{
Expand Down Expand Up @@ -606,6 +607,12 @@ protected virtual Sql<ISqlContext> 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<ISqlContext> GetBaseQuery(bool isCount) =>
GetBaseQuery(isCount ? QueryType.Count : QueryType.Single);
Expand Down Expand Up @@ -936,6 +943,8 @@ protected override void PersistUpdatedItem(IMember entity)

OnUowRefreshedEntity(new MemberRefreshNotification(entity, new EventMessages()));

_memberByUsernameCachePolicy.DeleteByUserName(UsernameCacheKey, entity.Username);

entity.ResetDirtyProperties();
}

Expand Down

0 comments on commit d451390

Please sign in to comment.