Performance in dynamic menus

1

I am putting together a cakephp and mysql application, and would like to display some menus and items dynamically through the database.

For example: View the latest updates, the latest database inserts, the menu with categories registered in the system, etc.

What happens:

-User accesses home, system requests menus to bank.

-User goes into some link, and the system requests the database again.

I understand that this way, with every get on the site, it will go into the database again, fetch this information to render the menus.

Doubt:

  • Is there any way to adjust for the system to create only one request in the database on user access, not overloading the database with selects for each link within the site?
  • Changing these requests for ajax would be a good solution?
  • Is Cakephp's CacheHelper able to assist in this in any way?
asked by anonymous 11.06.2014 / 22:25

1 answer

2

Single database request

The simplest way to do this in php is to load the menus in another way, for example: save the menu array to a serialized file in json, every time the site loads you only read this file if this file does not exist you do a select from the database and create it. Useful functions: json_encode(), json_decode, file_put_contents(), file_get_contents() .

The performance increases a lot and if you want to modify the menu, simply change the bank and delete the file.

Ajax requests

You can also load the menu in ajax and keep the persistent select on every request from the database, this does not increase the final result speed but will cause the page to load faster even though the menu may have a load delay.

These are just tips, but in a nutshell: yes you can leave faster.

  

"Just do a search on the database when it's really needed, use caching and indexing whenever possible"

    
11.06.2014 / 22:49