I'm thinking we should cache mega menus (have a cache switch in the admin area) so we aren't iterating through every menu item with every page load.

Comments

Anonymous’s picture

Title: Performance » Cache megas for performance
Anonymous’s picture

Will caching the block be sufficient?

GiorgosK’s picture

Yes very much needed feature

block cache is enabled on my system but I still see the menu be rebuilt on every page load ...

alexbk66-’s picture

I've done it for my site as I have 500 items in the menu. I'm using 'cache_menu' table so it get's cleared when cache is cleared.
Note: I also commented out 'i18nmenu_localize_tree', see http://drupal.org/node/1090256#comment-5683054
The page load time is reduced by 2 seconds and is now under one second, of course when the menu is already cached.

function theme_megamenu_menu_tree($menu_name) {
  global $language;
  
  $cache_key = 'megamenu:' . $menu_name . ':' . $language->language;
  $cache = cache_get($cache_key, );
  if ($cache && isset($cache->data)) {
    $menu = $cache->data;
  }
  else {
    $menutree = _megamenu_get_menu_tree($menu_name);
    //if (function_exists('i18nmenu_localize_tree')) {
    //  i18nmenu_localize_tree($menutree);
    //}
    $menu = theme_megamenu_menu_tree_helper($menu_name, $menutree, 1);
    cache_set($cache_key, $menu, 'cache_menu');
  }
  return $menu;
}

hobbyblob.com

bnobleman’s picture

The stuff below caches menu per user

function nobleprog_megamenu_menu_tree($menu_name) {
  global $language;
  global $user;
  
  $cache_key = 'megamenu:' . $menu_name . ':' . $language->language . $user->uid;
  $cache = cache_get($cache_key,'cache_menu' );
  if ($cache && isset($cache->data)) {
    $menu = $cache->data;
  }
  else {
    $menu = theme_megamenu_menu_tree($menu_name);
    cache_set($cache_key, $menu, 'cache_menu');
  }
  return $menu;
}

-------
Bernard Szlachta
http://www.nobleprog.co.uk/drupal/training
http://www.nobleprog.us/drupal-training-courses

ram4nd’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Issue summary: View changes
Status: Active » Fixed

I implemented block cache per page. Should be enough. If you want real speed, use boost or varnish. For non anonymous there is the block cache now.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.