1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Disabling cache for custom control

Disabling cache for custom control

5 posts, 0 answered
  1. JonnyP
    JonnyP avatar
    2 posts
    Registered:
    11 Jan 2011
    18 May 2011
    Link to this post
    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.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    24 May 2011
    Link to this post
    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
  3. Matthew
    Matthew avatar
    33 posts
    Registered:
    15 Dec 2008
    25 Jun 2011
    Link to this post
    Thanks, I had this same question and this seems to do the trick.
  4. kz
    kz avatar
    21 posts
    Registered:
    10 Jul 2009
    07 Oct 2011
    Link to this post
    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.


  5. kz
    kz avatar
    21 posts
    Registered:
    10 Jul 2009
    07 Oct 2011
    Link to this post
    I figured out something that worked. I dropped this in my InitializeControls method in my widget.

    System.Web.

     

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


5 posts, 0 answered