By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,421 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Cache Menu

P: n/a
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");

}
Aug 7 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" wrote:
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");

}
Aug 8 '07 #2

P: n/a
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 [C# MVP]" <pb*******@yahoo.yohohhoandabottleofrum.comwrote
in message news:08**********************************@microsof t.com...
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" wrote:
>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");

}

Aug 8 '07 #3

P: n/a
On Aug 8, 9:48 pm, "MikeB" <m...@nospam.comwrote:
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 [C# MVP]" <pbromb...@yahoo.yohohhoandabottleofrum.comwrote
in messagenews:08**********************************@m icrosoft.com...
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" wrote:
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.

Aug 9 '07 #4

P: n/a
On Aug 9, 9:14 am, Alexey Smirnov <alexey.smir...@gmail.comwrote:
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()

Aug 9 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.