views:

90

answers:

1

I am about to create a menu for a project of mine, and I need to make a dynamic navigation.

In my Admin back end, I will create a form for URI entry, so that the admins can create links and define the parent of the link and their ordering in relation to other links in the parent. I will be doing this with a MySQL database. The question here is:

Should I go with -

  • Dynamic menu created from a MySQL query, that would then be converted into an array, and passed into Zend_Navigation

    or

  • Dynamic menu created from an XML file, that would in turn be created at the moment of MySQL insert, and would therefore be a static file, which would be more easily cacheable

So basically, this is a question of speed and cache-ability. Which one of these would be faster?

+1  A: 

XML pros:

  • file is available when DB is offline

DB pros:

  • simpler syntax

Your assumption about caching is wrong, you will never send the XML to the user and let them cache it, you need to parse it in your application before the page is generated.

I would use cache and keep it alive for lifetime. You erase the cache when you update the navigation (save XML or insert into DB). The heavy lifting would be parsing XML or fetching data from DB, both are situations you want to happen as few times as possible and that's why you'd want to cache it.

The cached data could be in a file or RAM (faster); and since the XML-file already is a file you need to go further to really make use of the cache: interpret the XML and cache either

  • the Zend_Navigation instance (preferred); or
  • the config for Zend_Navigation
chelmertz
Well, my page would not work at all in case if the DB is down, so there seems no sense in trying to generate this XML file for the navigation. Thanks, I'll go with the DB.And thanks for the clarification on XML. I knew this, but somehow I got confused about the whole caching thing.
Janis Peisenieks
You could take a look at the examples of Zend_Cache in the reference manual, it's pretty easy to make use of. And I'd aim for cache in memory (like memcached/APC).
chelmertz