Cache Menu

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");

}
 
G

Guest

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
 
M

MikeB

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");

}
 
G

Guest

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.
 
G

Guest

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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top