0

We have an ASP.NET Web Forms Sitecore site, where we are using HTML output caching using the OutputCache directive, VaryByCustom attribute, and an added GetVaryByCustomString() method in Global.asax.

Is it possible to get a handle to the current control from the GetVaryByCustomString() method? We're running into a problem with output caching using this method and multiple instances of a control added to the same page. If I had a handle to the control, I could cache the output separately based on its Sitecore parameters (important in this case) and still make it mesh nicely with the rest of our caching strategy.

Iucounu
  • 1,630
  • 1
  • 20
  • 31

2 Answers2

0

I'm not sure why you would use custom code to do this caching. If you have a Sublayout for your control, then for each instance of that control/Sublayout on a page, you would activate caching by going to Presentation/Layout Details > Control Properties and scroll down to the Caching section. There you would check teh "Cacheable" and "Vary by Data" options.

Matthew Dresser
  • 11,273
  • 11
  • 76
  • 120
  • For one, Sitecore caching is known to have issues with postback, which unfortunately is used extensively throughout this codebase. It also doesn't work properly with some other scenarios, without going into needless detail. It's not that we don't understand how to use it, but that it has some drawbacks. When I'm able to redo the entire site in MVC in the coming year, things will be architected much differently. – Iucounu Dec 06 '16 at 21:03
0

It does not appear to be possible to get the currently evaluated code from GetVaryByCustomString() in Global.asax . However since my original goal was to vary cached output for a Sitecore control appearing multiple times in the same page, I found that this could be achieved by listing all controls in the page, then incrementing a counter attached to the request context during creation of each cache key and appending it to the key, since the controls are laid out in a deterministic and reliable order.

Iucounu
  • 1,630
  • 1
  • 20
  • 31