Note that there are some explanatory texts on larger screens.

plurals
  1. POVary Cache by URL for MVC Renderings?
    primarykey
    data
    text
    <p>With Sitecore 7, most of my query strings have become custom routes. For example:</p> <pre><code>OLD: /calendar?year=2013&amp;month=7&amp;day=14 NEW: /calendar/2013/7/14 </code></pre> <p>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?</p> <p><strong>UPDATE</strong></p> <p>I have found that all MVC renderings pass through the <strong>mvc.renderRendering</strong> pipeline, where their cache key is generated in the following class:</p> <p><code>Sitecore.Mvc.Pipelines.Response.RenderRendering.GenerateCacheKey</code></p> <p>By overriding the <code>GenerateKey(Rendering rendering, RenderRenderingArgs args)</code> method of this class, I am able to successfully append the raw URL using <code>site.Request.FilePath</code>. 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.</p> <p><strong>UPDATE 2</strong></p> <p>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)</p> <pre><code>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; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload