T
the4man
Hi all!!
I have a very stupid and simple project, just for testing, with only
one page (default.aspx), and one user control. The user control only
shows the time in an asp:literal each time the page is requested.
I want to cache the content of the user control (not the entire page),
and I want to invalidate that cache when I need. To do this, I have
added an "OuputCache" directive in my USER control. Furthermore I have
a button to invalidate the cache. This is the user control code:
protected void Page_Load(object sender, EventArgs e)
{
Literal1.Text = DateTime.Now.ToLongTimeString();
Response.AddCacheItemDependency("cachecontrol");
}
protected void Button1_Click(object sender, EventArgs e)
{
HttpContext.Current.Cache.Insert("cachecontrol", DateTime.Now);
Response.Redirect("~/Default.aspx");
}
In the global.asax, I have this:
void Application_Start(object sender, EventArgs e)
{
HttpContext.Current.Cache.Insert("cachecontrol", DateTime.Now);
}
This code is base in the examples of this article:
http://aspalliance.com/668
Well, it does not work. All my attemps to invalidate the cache of the
user control have been unsucessfull. Only if I put the "OutputCache"
directive in the default.aspx (what means cache the entire page) the
cache invalidation mechanism works.
Can anyone help me? How can I invalidate a partial-cached web page?
Thanks in advance!
I have a very stupid and simple project, just for testing, with only
one page (default.aspx), and one user control. The user control only
shows the time in an asp:literal each time the page is requested.
I want to cache the content of the user control (not the entire page),
and I want to invalidate that cache when I need. To do this, I have
added an "OuputCache" directive in my USER control. Furthermore I have
a button to invalidate the cache. This is the user control code:
protected void Page_Load(object sender, EventArgs e)
{
Literal1.Text = DateTime.Now.ToLongTimeString();
Response.AddCacheItemDependency("cachecontrol");
}
protected void Button1_Click(object sender, EventArgs e)
{
HttpContext.Current.Cache.Insert("cachecontrol", DateTime.Now);
Response.Redirect("~/Default.aspx");
}
In the global.asax, I have this:
void Application_Start(object sender, EventArgs e)
{
HttpContext.Current.Cache.Insert("cachecontrol", DateTime.Now);
}
This code is base in the examples of this article:
http://aspalliance.com/668
Well, it does not work. All my attemps to invalidate the cache of the
user control have been unsucessfull. Only if I put the "OutputCache"
directive in the default.aspx (what means cache the entire page) the
cache invalidation mechanism works.
Can anyone help me? How can I invalidate a partial-cached web page?
Thanks in advance!