Link to home
Start Free TrialLog in
Avatar of lexo
lexo

asked on

Best practice to build a very large dynamic menu in coldfusion

What is the best practice to create a dynamic menu using coldfusion and javascript.  I want the menu to call the db minimally and the menu must be able to branch out to several levels with onClick events.  The menu must load fast as there will be several thousand pages, so I am thinking that maybe the menu query results get stored in a session value? I'm not sure if this is a good technique.  A link to a tutorial will suffice to answer this question.
Avatar of dgrafx
dgrafx
Flag of United States of America image

I don't have a link to a tutorial but just create the session var like:
<cfif Not StructKeyExists(session,"menuList")>
<cfquery ... >
select ...
</cfquery>
<cfsavecontent variable="menuContent">
put your code that builds menu inside here
</cfsavecontent>
<cflock scope="session" type="exclusive" timeout="15">
<cfset session.menuList=menuContent>
</cflock>
</cfif>

#session.menuList#
Avatar of lexo
lexo

ASKER

Do you think that saving the data in a session variable like this is the best/fastest way to go?
much faster than not putting it in a session.
and as far as best practices -
if menu is always the same - meaning that one user sees the same menu as everyone else then I'd put it in the application scope
but if you have a members area (for ex) that is determined by a users login then it would need to be in a session
you'd setup a default menu to start and when and if user logs in then set their "session menu" is reset to whatever is applicable
 
Avatar of lexo

ASKER

Everyone would see the same menu, it is a public site.

Is this how it would be done?

<cfif Not StructKeyExists(application,"menuList")>
<cfquery ... >
select ...
</cfquery>
<cfsavecontent variable="menuContent">
put your code that builds menu inside here
</cfsavecontent>
<cflock scope="application" type="exclusive" timeout="15">
<cfset application.menuList=menuContent>
</cflock>
</cfif>

#application.menuList#
ASKER CERTIFIED SOLUTION
Avatar of dgrafx
dgrafx
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lexo

ASKER

Thank you.