diff --git a/modules/block/block.module b/modules/block/block.module index 70f55e5..c6aa248 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -836,19 +836,39 @@ function block_block_list_alter(&$blocks) { * An array of visible blocks as expected by drupal_render(). */ function _block_render_blocks($region_blocks) { - // Block caching is not compatible with node access modules. We also - // preserve the submission of forms in blocks, by fetching from cache only - // if the request method is 'GET' (or 'HEAD'). - $cacheable = !count(module_implements('node_grants')) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD'); + // Block caching is not compatible with node access modules by default but + // could be override. We also preserve the submission of forms in blocks, by + // fetching from cache only if the request method is 'GET' (or 'HEAD'). + $cacheable = (variable_get('block_cache_bypass_node_grants', FALSE) || !count(module_implements('node_grants'))) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD'); + + //First loop to get multiple block caches + $block_caches = array(); + if ($cacheable) { + + $cids = array(); + foreach ($region_blocks as $key => $block) { + if (!isset($block->content)) { + if (($cid = _block_get_cache_id($block))) { + $cids[] = $cid; + } + } + } + + if ($cids) { + $block_caches = cache_get_multiple($cids, 'cache_block'); + } + } + foreach ($region_blocks as $key => $block) { // Render the block content if it has not been created already. if (!isset($block->content)) { // Erase the block from the static array - we'll put it back if it has // content. unset($region_blocks[$key]); - // Try fetching the block from cache. - if ($cacheable && ($cid = _block_get_cache_id($block)) && ($cache = cache_get($cid, 'cache_block'))) { - $array = $cache->data; + + // Try fetching the block from cache previously loaded. + if (($cid = _block_get_cache_id($block)) && (array_key_exists($cid, $block_caches))) { + $array = $block_caches[$cid]->data; } else { $array = module_invoke($block->module, 'block_view', $block->delta); @@ -1013,13 +1033,13 @@ function block_menu_delete($menu) { * Implements hook_form_FORM_ID_alter(). */ function block_form_system_performance_settings_alter(&$form, &$form_state) { - $disabled = count(module_implements('node_grants')); + $disabled = (variable_get('block_cache_bypass_node_grants', FALSE) || count(module_implements('node_grants'))); $form['caching']['block_cache'] = array( '#type' => 'checkbox', '#title' => t('Cache blocks'), '#default_value' => variable_get('block_cache', FALSE), '#disabled' => $disabled, - '#description' => $disabled ? t('Block caching is inactive because you have enabled modules defining content access restrictions.') : NULL, + '#description' => $disabled ? t('Block caching is inactive because you have enabled modules defining content access restrictions.') . ' '. t('Anyway, if you want to bypass this default behavior, you could override it by setting to TRUE variable "block_cache_bypass_node_grants".') : NULL, '#weight' => -1, ); }