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
source to share
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_
.
source to share