Skip to content

Instantly share code, notes, and snippets.

@casper-rasmussen
Created March 20, 2016 22:22
Show Gist options
  • Save casper-rasmussen/20c50295fcc03e62f0a3 to your computer and use it in GitHub Desktop.
Save casper-rasmussen/20c50295fcc03e62f0a3 to your computer and use it in GitHub Desktop.
class EPiServerAwareKeyBuilder : IKeyBuilder
{
private readonly IKeyBuilder _keyBuilder = new KeyBuilder();
public string BuildKey(string controllerName)
{
return this._keyBuilder.BuildKey(controllerName);
}
public string BuildKey(string controllerName, string actionName)
{
return this._keyBuilder.BuildKey(controllerName, actionName);
}
public string BuildKey(string controllerName, string actionName, RouteValueDictionary routeValues)
{
return this._keyBuilder.BuildKey(controllerName, actionName, routeValues);
}
public string BuildKeyFragment(KeyValuePair<string, object> routeValue)
{
string cacheValue = "<null>";
if (routeValue.Value != null)
{
//If its the currentContent value
if (routeValue.Key.Equals("currentcontent"))
{
IContent content = routeValue.Value as IContent;
if (content != null)
{
cacheValue = content.ContentLink.ID.ToString();
}
}
else
{
//Just get string representation of any other value
cacheValue = routeValue.Value.ToString().ToLowerInvariant();
}
}
return string.Format("{0}={1}#", routeValue.Key.ToLowerInvariant(), cacheValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment