3
votes

Is it possible to change the output cache and it's duration for specific control, from code-behind?

I mean, let's say I have control News.ascx that has:

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

Now I want to write somewhere some code, that will decide dynamically if use output cache and what will be the duration of that cache. Is it possible?

I thought, that I will able to use custom OutputCacheProvider that described on CodeProject, but I can't find a way how to do it.

1

1 Answers

0
votes

you can do it see details here http://support.microsoft.com/kb/323290

Use response.cache as

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

See a similar question Conditionally add OutputCache Directive