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"
;
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
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: