Different output cache timeout for different usercontrols
I have s开发者_如何学Goeveral usercontrols which I would like to have a different output cache timeout.
I have tried the following but without success:
- Set cacheprofile (can apparently only be done on aspx pages).
Do the following in codebehind:
Response.Cache.SetExpires(DateTime.Now.AddDays(OutputCaching.QuickTimeout))
Response.Cache.SetCacheability(HttpCacheability.Public)
Response.Cache.SetValidUntilExpires(true);
Response.Cache.VaryByParams.IgnoreParams = true;
Apparently only <%@ OutputCache Duration="6000" VaryByParam="" %>
works, but isn't there a way to take the duration from a config- or appsettings file?
Technically it is possible based on the Remarks of this article but is think that
HttpCacheability.Server = @ OutputCache
instead of
HttpCacheability.Public
Here is the doc for HttpCacheability, this will help you pick the right choice for you.
Also I think it would be best if you put your code in the Page_Init or Page_PreInit like this:
Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
Me.Response.Cache.SetCacheability(HttpCacheability.Server)
Me.Response.Cache.SetExpires(Date.Now.AddMinutes(10))
Me.Response.Cache.SetValidUntilExpires(True)
Me.Response.Cache.VaryByParams.IgnoreParams = True
End Sub
Regards,
精彩评论