Created
September 21, 2023 07:48
-
-
Save trnktms/f1a3f41f848bac0210d32c7818c45c89 to your computer and use it in GitHub Desktop.
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
public class WildcardApiPublishedContentCache : IApiPublishedContentCache | |
{ | |
private const char SplitChar = '/'; | |
private const string WildcardName = "star"; | |
private readonly ApiPublishedContentCache _apiPublishedContentCache; | |
public WildcardApiPublishedContentCache(ApiPublishedContentCache apiPublishedContentCache) | |
{ | |
_apiPublishedContentCache = apiPublishedContentCache; | |
} | |
public IPublishedContent? GetById(Guid contentId) | |
{ | |
return _apiPublishedContentCache.GetById(contentId); | |
} | |
public IEnumerable<IPublishedContent> GetByIds(IEnumerable<Guid> contentIds) | |
{ | |
return _apiPublishedContentCache.GetByIds(contentIds); | |
} | |
public IPublishedContent? GetByRoute(string route) | |
{ | |
var content = _apiPublishedContentCache.GetByRoute(route); | |
if (content == null) | |
{ | |
// Try to get a wildcard item if exists | |
var routePath = route.Split(SplitChar); | |
var wildcardRoute = string.Join(SplitChar, new List<string>(routePath.Take(routePath.Length - 1)) { WildcardName }); | |
content = _apiPublishedContentCache.GetByRoute(wildcardRoute); | |
} | |
return content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment