With Sitecore 7, most of my query strings have become custom routes. For example:
OLD: /calendar?year=2013&month=7&day=14
NEW: /calendar/2013/7/14
As a result, I find myself in need of varying the HTML cache of my renderings by URL, rather than by query string. Does Sitecore provide a convenient way of varying cache by URL for MVC renderings?
UPDATE
I have found that all MVC renderings pass through the mvc.renderRendering pipeline, where their cache key is generated in the following class:
Sitecore.Mvc.Pipelines.Response.RenderRendering.GenerateCacheKey
By overriding the GenerateKey(Rendering rendering, RenderRenderingArgs args)
method of this class, I am able to successfully append the raw URL using site.Request.FilePath
. The problem I face now is how do I extract this cache setting from the rendering itself? I think I need to create a new "VaryByUrl" caching option on the rendering, but i'm not quite sure.
UPDATE 2
I was able to read a custom field off of the rendering definition item using the following code. It works, but it only looks at the definition item (not the actual instance of the rendering in the presentation details)
protected override string GenerateKey(Rendering rendering, RenderRenderingArgs args)
{
var key = base.GenerateKey(rendering, args);
if (rendering.RenderingItem.InnerItem.Fields["VaryByUrl"] != null)
{
var varyByUrl = ((CheckboxField)rendering.RenderingItem.InnerItem.Fields["VaryByUrl"]).Checked;
if (varyByUrl) key += GetUrlPart(rendering);
}
return key;
}