Disable cache for a widget - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Disable cache for a widget

  • Disable cache for a widget
  • 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.
  • 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 >>
  • 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?
  • 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 >>
  • 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?

  • 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...
  • 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"%>


  • 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?