Caching Problems
-
Hey All, I'm having a little trouble with caching in ASP.NET and I wonder if somebody could tell me if what I'm trying to do should work. From my understanding of the MSDN documentation it should but it doesn't seem to be so maybe I'm doing something wrong. I have an ASP.NET page that contains a number of custom controls but there is only 1 that I'm interested in caching but two controls are involved. 1: A header control with a drop down list (not being cached) 2: A menu control (certain items depend on the value in the drop down list in the header control)(trying to cache) The menu control has a public property called
Location
and I'm using programatic caching (attributes) and theMenu
class is adorned withPartialCaching
attribute as shown here:[PartialCaching(100, null, "Location", null)]
public class Menu : System.Web.UI.UserControl
{
public string Location
{
get
{
return m_location;
}
set
{
m_location = value;
}
}. . .
In the above attribute the third paramater is the
VaryByControl
paramater so it should in effect allow me to control cahcing of this control based on the value of theLocation
property. TheLocation
property is being set by the page that contains this control and by debugging I see that the sequence of events that happens manages to se theLocation
property of the menu control before theOnInit
is called in the menu control (Debugging confirmed that it is indeed being set correctly). My understanding is that theOnInit
is called just after the viewstate data has been received but if I'm wrong and it's reinitialising the entire page then that is probably my problem but I can't find any info in the MSDN on exactly what it does. As far as I can see this should cause the caching to occour with the desired effect.. i.e. different caches dependent upon the value of theLocation
property that is set before theOnInit
of the menu control is called.... What actually happens is the first time the page loads the menu control is cached and then servered from the cache for the next 100 seconds regardless of what I set theLocation
property of the control too... I though the point ofVaryByControl
was to deal with situations exactly like this? Am I missing something really simple here?? I don't normally do ASP.NET stuff so I'm not entirely sure of the sequenc