Disable cache for a widget

Posted by Community Admin on 05-Aug-2018 08:46

Disable cache for a widget

All Replies

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

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.

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

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

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

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?

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

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

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

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?

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

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...

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

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


Posted by Community Admin on 04-Apr-2012 00:00

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?

This thread is closed