ASP.NET - 服务器控件输出缓存

3

是否可以在代码后端更改特定控件的输出缓存及其持续时间?

我的意思是,假设我有一个名为News.ascx的控件,其中包含:

<%@ OutputCache Duration="60" VaryByCustom="language" %>

现在我想在某个地方编写一些代码,以动态方式决定是否使用输出缓存以及该缓存的持续时间。这可能吗?

我认为,我将能够使用在CodeProject上描述的自定义OutputCacheProvider,但我找不到如何做到这一点的方法。

1个回答

0

你可以做到,详情请参见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); 
}

查看类似问题有条件地添加OutputCache指令


1
谢谢,但我不确定它是否有效。如果我使用HttpContext.Current.Response.Cache,我认为它会缓存整个页面的输出,但我想要操作页面上特定控件的缓存而不是整个页面。该页面有许多无法缓存的元素。 - Alex Dn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接