diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-01-04 04:47:24 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-01-04 04:47:24 +0000 |
commit | ea064e3e8fffa3d9de435f801a489de7a95af14a (patch) | |
tree | 303ce0a382ce33d0420ab462eea70ac2c27224ed | |
parent | 37b78e02594e95ac059a69fe47ee62bf24ce5db5 (diff) | |
download | brdo-ea064e3e8fffa3d9de435f801a489de7a95af14a.tar.gz brdo-ea064e3e8fffa3d9de435f801a489de7a95af14a.tar.bz2 |
#643984 by catch: Cache results of menu_get_item(). This makes it possible to serve a page in Drupal 7 with no hits to the database when using alternate caching backends.
-rw-r--r-- | includes/menu.inc | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/includes/menu.inc b/includes/menu.inc index b04955ca0..38168bcc7 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -403,13 +403,17 @@ function menu_get_item($path = NULL, $router_item = NULL) { $original_map = arg(NULL, $path); $parts = array_slice($original_map, 0, MENU_MAX_PARTS); $ancestors = menu_get_ancestors($parts); - $router_item = db_select('menu_router') - ->fields('menu_router') - ->condition('path', $ancestors, 'IN') - ->orderBy('fit', 'DESC') - ->range(0, 1) - ->addTag('menu_get_item') - ->execute()->fetchAssoc(); + + // Since there is no limit to the length of $path, but the cids are + // restricted to 255 characters, use md5() to keep it short yet unique. + $cid = 'menu_item:' . md5($path); + if ($cached = cache_get($cid, 'cache_menu')) { + $router_item = $cached->data; + } + else { + $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc(); + cache_set($cid, $router_item, 'cache_menu'); + } if ($router_item) { $map = _menu_translate($router_item, $original_map); $router_item['original_map'] = $original_map; |