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

Forums / Sitefinity SDK / Disable cache for a widget

Disable cache for a widget

8 posts, 0 answered
  1. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    04 May 2011
    Link to this post
    Is there a way to disable the cache for a particular widget? I'm having trouble displaying personalized content to users as it appears to be displaying the cached version of a page to all users.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 May 2011
    Link to this post
    Hi Ryan,

    There is  way to do this, but you need a custom control - cache substitution control

    sample

    <asp:substitution id="Substitution1"
     methodname="GetCurrentUser"
     runat="server">
    </asp:substitution>

    public static string GetCurrentUser(HttpContext context)
     
      {
     
          if(context.User.Identity.IsAuthenticated)
     
              return context.User.Identity.Name;
     
          return "some string";
     
      }
     


    otherwise you should disable the caching on this page.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    04 May 2011
    Link to this post
    That doesn't look like it'll be suitable as it's the entire content of the widget that can change, so the only option is to disable caching on every page?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 May 2011
    Link to this post
    Hello Ryan,

    For the substitution control, it does not matter what you are going to change, since it would not be affected by the caching. If you think that this would not work, the page caching should be disabled on this page.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  5. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    04 May 2011
    Link to this post
    I've tried adding <%@OutputCache Duration="120" VaryByParam="none" VaryByCustom="customfield"%> to the control but GetVaryByCustomString in the global.asax isn't firing. Any idea why that would be?

  6. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    04 May 2011
    Link to this post
    Okay, I might have solved it by added the VaryByParam as a class attribute instead of declaring it in the ascx:

    [PartialCaching(60, null, null, "customfield")]

    This does cause the GetVaryByParam method to be called in the global.asax. I'll keep testing...
  7. kz
    kz avatar
    21 posts
    Registered:
    10 Jul 2009
    07 Oct 2011
    Link to this post
    Did you ever have any luck with this? My global only fires once then it seems to cache until expiration.

    I've tried both [PartialCaching(60, null, null, "customfield")]

    and <%@OutputCache Duration="120" VaryByParam="none" VaryByCustom="customfield"%>


  8. Kunal Johar
    Kunal Johar avatar
    8 posts
    Registered:
    22 Jan 2010
    04 Apr 2012
    Link to this post
    I tried to use the substitution control but I am getting this error:

    Post cache substitution is not compatible with modules in the IIS integrated pipeline that modify the response buffers.  Either a native module in the pipeline has modified an HTTP_DATA_CHUNK structure associated with a managed post cache substitution callback

    Any tips?
8 posts, 0 answered