3

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.

Marcel
  • 14,086
  • 19
  • 84
  • 137
Alex Dn
  • 5,333
  • 7
  • 38
  • 77

1 Answers1

0

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

Community
  • 1
  • 1
Ratna
  • 2,234
  • 2
  • 24
  • 48
  • 1
    Thank you, but I am not sure it will work. If I will use HttpContext.Current.Response.Cache, I think it will cache the whole output for the page, but I trying to manipulate cache just for specific controls on page and not whole page. The page has many elements that can not be cached. – Alex Dn May 27 '13 at 12:09