Cache Menu

  • Thread starter Thread starter MikeB
  • Start date Start date
M

MikeB

Hello All, I am trying to cache a menu that I dynamically build out and I do
not want to have to build it out each time the page loads. Here is how I am
doing it however, it doesnt work. Can anyone help? TIA

if (Cache["Menu"] == null)

{

THIS IS WHERE I BUILD OUT THE MENU ITEMS



Cache.Insert("Menu",Menu1); **** Menu1 is the menu control in the web page

}

else

{

Menu1 = (Menu)Cache.Get("Menu");

}
 
When you say "it doesn't work", what do you mean? Does the Cache Item get
populated? Have you tried setting a breakpoint on this code and stepping
through it to examine each object on each line to see what the values are?
Maybe your code is throwing an exception - but I don't see any exception
handling code in your sample.

-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com
 
Yes, I have stepped through and there is no exception thrown. It just
doen't fill the menu with anything when I set it here:

Menu1 = (Menu)Cache.Get("Menu");


Peter Bromberg said:
When you say "it doesn't work", what do you mean? Does the Cache Item get
populated? Have you tried setting a breakpoint on this code and stepping
through it to examine each object on each line to see what the values are?
Maybe your code is throwing an exception - but I don't see any exception
handling code in your sample.

-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com



MikeB said:
Hello All, I am trying to cache a menu that I dynamically build out and I
do
not want to have to build it out each time the page loads. Here is how I
am
doing it however, it doesnt work. Can anyone help? TIA

if (Cache["Menu"] == null)

{

THIS IS WHERE I BUILD OUT THE MENU ITEMS



Cache.Insert("Menu",Menu1); **** Menu1 is the menu control in the web
page

}

else

{

Menu1 = (Menu)Cache.Get("Menu");

}
 
Yes, I have stepped through and there is no exception thrown. It just
doen't fill the menu with anything when I set it here:

Menu1 = (Menu)Cache.Get("Menu");

in message

When you say "it doesn't work", what do you mean? Does the Cache Item get
populated? Have you tried setting a breakpoint on this code and stepping
through it to examine each object on each line to see what the values are?
Maybe your code is throwing an exception - but I don't see any exception
handling code in your sample.
Hello All, I am trying to cache a menu that I dynamically build out and I
do
not want to have to build it out each time the page loads. Here is how I
am
doing it however, it doesnt work. Can anyone help? TIA
if (Cache["Menu"] == null)
{
THIS IS WHERE I BUILD OUT THE MENU ITEMS
Cache.Insert("Menu",Menu1); **** Menu1 is the menu control in the web
page
}
else
{
Menu1 = (Menu)Cache.Get("Menu");
}- Hide quoted text -

- Show quoted text -

Try this

if (Cache["Menu"] == null)
{
Cache.Insert("Menu",Menu1);
}
Menu1 = (Menu)Cache.Get("Menu");

At the first time when cache is empty you didn't populate the menu.
 
Try this

if (Cache["Menu"] == null)
{
Cache.Insert("Menu",Menu1);}

Menu1 = (Menu)Cache.Get("Menu");

At the first time when cache is empty you didn't populate the menu.

I think I was too fast with my answer, because now I see, it seems you
always have "Menu1". Check if Menu1 is not null at Cache.Insert()
 
Back
Top