是否可以从代码隐藏更改输出缓存及其特定控制的持续时间?
我的意思是,假设我有控制 News.ascx
有:
<%@ OutputCache Duration="60" VaryByCustom="language" %>
现在我想在某个地方写一些代码,它将动态决定是否使用输出缓存以及该缓存的持续时间。可能吗?
我想,我将能够使用在 CodeProject 上描述的自定义 OutputCacheProvider
, 但我找不到方法。
最佳答案
您可以在此处查看详细信息 http://support.microsoft.com/kb/323290
使用response.cache作为
if (x==y)
{
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddSeconds(6700));
HttpContext.Current.Response.Cache.SetValidUntilExpires(true);
}
见类似问题Conditionally add OutputCache Directive
https://stackoverflow.com/questions/16771611/