-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cache key to GetByUserName (#17350)
* Add cache key to GetByUserName * Remove constants * create new cache policy for member repository --------- Co-authored-by: Elitsa <[email protected]>
- Loading branch information
Showing
2 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/Umbraco.Infrastructure/Cache/MemberRepositoryUsernameCachePolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Umbraco.Cms.Core.Models; | ||
using Umbraco.Cms.Infrastructure.Scoping; | ||
using Umbraco.Extensions; | ||
|
||
namespace Umbraco.Cms.Core.Cache; | ||
|
||
public class MemberRepositoryUsernameCachePolicy : DefaultRepositoryCachePolicy<IMember, string> | ||
{ | ||
public MemberRepositoryUsernameCachePolicy(IAppPolicyCache cache, IScopeAccessor scopeAccessor, RepositoryCachePolicyOptions options) : base(cache, scopeAccessor, options) | ||
{ | ||
} | ||
|
||
public IMember? GetByUserName(string key, string? username, Func<string?, IMember?> performGetByUsername, Func<string[]?, IEnumerable<IMember>?> performGetAll) | ||
{ | ||
var cacheKey = GetEntityCacheKey(key + username); | ||
IMember? fromCache = Cache.GetCacheItem<IMember>(cacheKey); | ||
|
||
// if found in cache then return else fetch and cache | ||
if (fromCache != null) | ||
{ | ||
return fromCache; | ||
} | ||
|
||
IMember? entity = performGetByUsername(username); | ||
|
||
if (entity != null && entity.HasIdentity) | ||
{ | ||
InsertEntity(cacheKey, entity); | ||
} | ||
|
||
return entity; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters