Disable caching for a rendering on some pages
Everyone loves Sitecore caching capabilities, especially HTML Caching, where you can cache the output HTML of any rendering.
When you want to cache any rendering, you have two options:
I found a solution for this, where you can disable any caching setting for any rendering, :
Leave your feedback in the comments!
When you want to cache any rendering, you have two options:
- On rendering definition item, Set 'Cacheable' checkbox
- On item presentation details, Select your rendering and set 'Cacheable' checkbox.
I found a solution for this, where you can disable any caching setting for any rendering, :
- Create a new rendering parameters template which includes a checkbox field called "Cancel Cache Settings'
- Go to your rendering definition item, and set the parameter template to the new template
- If your site runs on Sitecore MVC, Do the following
- Create a class called 'SetCacheability' :
namespace Sitecore.SharedResources.Pipelines.Rendering { public class SetCacheability : Sitecore.Mvc.Pipelines.Response.RenderRendering.SetCacheability { protected override bool IsCacheable(Sitecore.Mvc.Presentation.Rendering rendering, Sitecore.Mvc.Pipelines.Response.RenderRendering.RenderRenderingArgs args) { if (!String.IsNullOrEmpty(rendering.Parameters["Cancel Cache Settings"]) && rendering.Parameters["Cancel Cache Settings"] == "1") { return false; } return base.IsCacheable(rendering, args); } } }
- Create a config file inside your 'Include' folder:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <pipelines> <mvc.renderRendering> <processor patch:instead="processor[@type='Sitecore.Mvc.Pipelines.Response.RenderRendering.SetCacheability, Sitecore.Mvc']" type="Sitecore.SharedResources.Pipelines.Rendering.SetCacheability, [YOUR ASSEMBLY NAME]"/> </mvc.renderRendering> </pipelines> </sitecore> </configuration>
- If your code runs on ASP.NET forms:
- Add the following code to your sublayout code:
private NameValueCollection _Parameters; public NameValueCollection Parameters { get { if (_Parameters != null) { Sublayout sublayout = Parent as Sublayout; _Parameters = Sitecore.Web.WebUtil.ParseUrlParameters(sublayout.Parameters); } return Parameters; } } public override bool Cacheable { get { if (!string.IsNullOrEmpty(Parameters["Cancel Cache Settings"]) && Parameters["Cancel Cache Settings"] == "1") { return false; } return base.Cacheable; } set { base.Cacheable = value; } }
Leave your feedback in the comments!
Comments
Post a Comment