2

I have a component on my site called "Menu" along with a corresponding content item "MenuContent" which is used in the header and footer of each page. The rendering makes use of the placeholder path to determine its location within the page and change certain properties accordingly (for analytics purposes). What I am finding is that when this component has caching enabled (on the Rendering definition item: Cacheable, Vary By Data both checked) it caches the first instance and uses that for the header and footer. I presume the Vary by Data option varies the cache depending on the datasource item, so Sitecore uses the same cached HTML for both, even though both should have different HTML. What cache setting should I use here and will I need to change my code to make that work?

1 Answer 1

5

The caching needed is Vary by Param.

From this article: https://sitecorebasics.wordpress.com/2011/10/30/basics-of-html-caching/

Vary: Vary by Param

Description: Sitecore cahces the output for each parameter accepted by the rendering

I was able to achieve the required result by checking the "Vary by Param" option (in addition to "Vary by Data") on the rendering definition item. In the places where the rendering was used, I simply added one extra parameter in the Parameters field of the rendering properties, making sure the value of the parameter was different for the different places it was used. The parameter was not used in code anywhere, so no code changes were required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.