473,796 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Partial Caching AddCacheItemDep endency 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(objec t sender, EventArgs e)
{
Literal1.Text = DateTime.Now.To LongTimeString( );
Response.AddCac heItemDependenc y("cachecontrol ");
}
protected void Button1_Click(o bject sender, EventArgs e)
{
HttpContext.Cur rent.Cache.Inse rt("cachecontro l", DateTime.Now);
Response.Redire ct("~/Default.aspx");
}

In the global.asax, I have this:

void Application_Sta rt(object sender, EventArgs e)
{
HttpContext.Cur rent.Cache.Inse rt("cachecontro l", 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 "OutputCach e"
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 3009
Answer my self:
From microsoft.com

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

You cannot call the AddCacheItemDep endency 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(objec t sender, EventArgs e)
{
Literal1.Text = DateTime.Now.To LongTimeString( );
String[] dependencyKey = new String[1];
dependencyKey[0] = "cachecontr ol";

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

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

HttpRuntime.Cac he.Insert("cach econtrol", DateTime.Now)

Global.asax:

void Application_Sta rt(object sender, EventArgs e)
{
HttpRuntime.Cac he.Insert("cach econtrol", DateTime.Now);
}

Feb 22 '06 #2

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

Similar topics

9
2534
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. I.e. do we have to need to write:
0
1245
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 etc) 2) UserID : int, Stored in session This combo is user specific so that each user has different combo contents for different groupkeys, but these would not change for the user for a groupkey.
0
1613
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 data does change very frequently). However, on occasion the web service doesn't return data, and I'd like to either continue to use the cache copy, or make sure that the user control does not get cached at the time where the web service failed. Is...
3
1643
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 calculated on the fly when the request is made, and so I thought it would be ideal to cache the page for a set amount of time. I've placed the following at the top of my page: <%@ OutputCache Duration="160" VaryByParam="None" %> Now the problem is...
10
2446
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 load as a 3rd partial class. This would be handy so i can generate standard code into one of the partial classes, while having my custom code untouched
6
2761
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 file dependency and assign it to Dependency property.
4
2986
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... now I dont know if doing the PHP caching is worth the pain. Would there be any noticed performace improvement if I cache query results in PHP, considering that MySQL is already caching the queries? Thanks
1
1199
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 used in a Master Page. Everything was working fine without caching but after caching the control, it is throwing null referance errors randomly.
1
1711
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 create a cache for it: <%@ OutputCache Duration="600" VaryByParam="None" SqlDependency="EMAMDB:EMAM_Clients" %> The cache will thus be invalidated every 10 min and also depending on the changes to the EMAM_Clients table which has only one entry.
0
10459
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10236
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10017
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.