Skip to content

Instantly share code, notes, and snippets.

@weirdpattern
Last active August 7, 2018 03:46
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 weirdpattern/053e37fcb2137d82b7a8821ef972c73e to your computer and use it in GitHub Desktop.
Save weirdpattern/053e37fcb2137d82b7a8821ef972c73e to your computer and use it in GitHub Desktop.
/// <summary>
/// Sets the cacheability of a rendering.
/// </summary>
public class SetCacheability : Sitecore.Mvc.Pipelines.Response.RenderRendering.SetCacheability
{
/// <inheritdoc />
protected override bool IsCacheable(Rendering rendering, RenderRenderingArgs args)
{
Assert.ArgumentNotNull(rendering, nameof(rendering));
var disableCaching = rendering.Parameters[Templates.Pipelines.SetCacheability.DisableCaching];
if (!string.IsNullorWhiteSpace(disableCaching) && disableCaching == "1")
{
return false;
}
return base.IsCacheable(rendering, args);
}
}
<?xml version="1.0" encoding="utf-8">
<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="MyCustom.Assembly.Pipelines.RenderRendering.SetCacheability, MyCustom.Assembly" />
</mvc.renderRendering>
</pipelines>
</sitecore>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment