Skip to content

Instantly share code, notes, and snippets.

@trnktms
Created September 21, 2023 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trnktms/f1a3f41f848bac0210d32c7818c45c89 to your computer and use it in GitHub Desktop.
Save trnktms/f1a3f41f848bac0210d32c7818c45c89 to your computer and use it in GitHub Desktop.
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