Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i enable caching for a Sitecore ControllerRendering

Is there a way to enable Sitecore caching for a ControllerRendering declared statically in a layout? In Webforms you could declare a rendering's caching settings like this:

<sc:Sublayout ID="slMyControl" path="~/path/to/my/control.ascx" VaryByParm="true" Cachable="true" runat="server" />

However, when I use the Html helper there is no overload on the Controller method to accept caching parameters?

@Html.Sitecore().Controller("NAMESPACE", "ACTION")

I'm running Sitecore 7.2

like image 245
Rob Earlam Avatar asked May 30 '26 01:05

Rob Earlam


1 Answers

If you want statically bind a controller rendering, you should use the Rendering() method on the html helper. There you can define the caching with parameters:

@Html.Sitecore().Rendering("<your rendering definition item id>", new { Cacheable = true, CacheKey = "my_rendering", Cache_VaryByData = true })

The parameters should have the same name as used in the sublayout, with a Cache_ prefix.

like image 111
Kevin Brechbühl Avatar answered Jun 01 '26 20:06

Kevin Brechbühl