473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Partial Caching AddCacheItemDependency problem

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!

Feb 22 '06 #1
1 2990
Answer my self:
From microsoft.com

(http://msdn2.microsoft.com/en-us/library/t1d120ks.aspx ):

You cannot call the AddCacheItemDependency method in an ASP.NET user
control. However, in any user control that specifies the @ OutputCache
directive, you can create a CacheDependency object that describes the
cache key dependency and assign it to the Dependency property of the
UserControl object.

solution:

User control code:

protected void Page_Load(object sender, EventArgs e)
{
Literal1.Text = DateTime.Now.ToLongTimeString();
String[] dependencyKey = new String[1];
dependencyKey[0] = "cachecontrol";

BasePartialCachingControl pcc = Parent as
BasePartialCachingControl;
pcc.Dependency = new CacheDependency(null,
dependencyKey);
}

Default.aspx code (note that now the button to invalidate the cache is
outside the user control):

HttpRuntime.Cache.Insert("cachecontrol", DateTime.Now)

Global.asax:

void Application_Start(object sender, EventArgs e)
{
HttpRuntime.Cache.Insert("cachecontrol", DateTime.Now);
}

Feb 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Gomaw Beoyr | last post by:
Two question about the "partial classes" (in the next wersion of ..NET). Question 1 ========== Will partial classes (in the next version of C#) have to be declared "partial" in ALL places. ...
0
by: Manish Jain | last post by:
I am trying to implement Partical Caching in a User Control that gets data from DB and populates a combo based on: 1) GroupKey : An int Property that is known for each call (say Source=10, Code=11...
0
by: Ryan Gregg | last post by:
I'm working with a user control that hits a web service and builds a result from that. I'd like to use partial caching to cache the object to prevent a heavy load on the web service (since the...
3
by: Janaka | last post by:
Hi All, I'm having a problem with Page Output caching on a page that contains a DataGrid. Basically the page pulls up some data for sales information from the DB. Some of this has to be...
10
by: ptass | last post by:
Hi In asp.net 2.0 an aspx files .cs file is a partial class and all works fine, however, I thought I’d be able to create another class file, call it a partial class and have that compile and...
6
by: Rolf Welskes | last post by:
Hello, I want to partial cache by using a UserControl. Now I have a file dependency. In msdn I see it is not possible to do it the same way as in a page. The only information is to create a...
4
by: Hermann | last post by:
My site is a bit slow showing the main page so I thought caching query result in PHP will improve performace. Then I read MySQL documentation and saw that MySQL does have a caching feature. So......
1
by: priya0123 | last post by:
Hi, We are writing an application in asp.net 2.0. We have used menu control and made it a usercontrol. I have Partial cached the user control. After caching the user control, this is being...
1
by: yashgt | last post by:
Hi, We have a control Logo.ascx, which queries the DB to obtain the logo image from a blob in the DB and renders it on the page. The logo does not change frequently and hence we have tried to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.