Disabling cache for custom control

Posted by Community Admin on 04-Aug-2018 12:17

Disabling cache for custom control

All Replies

Posted by Community Admin on 18-May-2011 00:00

This MUST have been solved by someone, somewhere, but I can't seem to get around it. 

I have a custom control, derived from SimpleView, which renders different content in it's template dependent upon the value inside a cookie. However, the caching kicks in and caches the output of the control on the first load and from then on, even if the cookie changes (and therefore should cause different content to be rendered), the same original content is displayed. 

I have tried using the <asp:substitution> control, but this can't access the callback method in the class from within the template file.

I have tried putting <%@ OutputCache Duration="0" %> in the template file, but this has no effect.

To make the desired output show correctly I have switched off the caching on the page, which is not at all ideal as the page is noticably slower without caching.

Any help from some clever person out there would be great.

Posted by Community Admin on 24-May-2011 00:00

Hello JonnyP,


Can you try using the code below

protected override void InitializeControls(GenericContainer container)
       
 
 
           Context.Response.WriteSubstitution(new HttpResponseSubstitutionCallback(SubMethod));
 
       
 
 
       public static string SubMethod(HttpContext context)
       
           return string.Empty;
       

HttpResponse.WriteSubstitution Method - Allows insertion of response substitution blocks into the response, which allows dynamic generation of specified response regions for output cached responses.

Kind regards,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 25-Jun-2011 00:00

Thanks, I had this same question and this seems to do the trick.

Posted by Community Admin on 07-Oct-2011 00:00

So is write subsitution the only way to do this our can one use the outputcache or Partial cache in the widget user control?

Using write subsitution is a pretty tricky method if you have complex widget and aren't just changing small text.


Posted by Community Admin on 07-Oct-2011 00:00

I figured out something that worked. I dropped this in my InitializeControls method in my widget.

System.Web.

 

HttpContext.Current.Response.Cache.SetVaryByCustom("customfield");


This thread is closed