2013-05-27 58 views
2

是否有可能更改输出缓存,以及它的持续时间为特定的控制,从代码隐藏?ASP.NET - 服务器控制输出缓存

我的意思是,让我们说我有控制有:

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

现在我想的地方写一些代码,这将决定动态,如果使用输出缓存,什么将是缓存的持续时间。可能吗?

我想,我将能够使用CodeProject上描述的自定义OutputCacheProvider,但我无法找到如何去做的方法。

回答

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); 
} 

看到类似的问题Conditionally add OutputCache Directive

+1

谢谢,但我不知道它会工作。如果我将使用HttpContext.Current.Response.Cache,我认为它会缓存页面的整个输出,但我试图操作缓存,仅用于页面上的特定控件而不是整个页面。该页面有许多无法缓存的元素。 –