How to enable caching for Sitecore ControllerRendering

Is there a way to enable Sitecore caching for ControllerRendering that is declared statically in the layout? In Webforms, you can declare display 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 Controller method overload to accept caching options?

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

I am running Sitecore 7.2

+3


source to share


2 answers


If you want to statically link the rendering to the controller, you must use the method Rendering()

for the html helper. There you can define caching with parameters:

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

      



The parameters must have the same name as the subarea, with a prefix Cache_

.

+11


source


It works and I tried it with Controller rendering. You can test it by tying it to a workflow and it shouldn't hit a breakpoint when you refresh the same page. It will also depend on what parameters were used for caching.



0


source







All Articles