diff --git a/modules/block/block.module b/modules/block/block.module
index ff77d9e..6fed57b 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -836,19 +836,41 @@ 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');
+
+ // Proceed to a loop over all blocks in order to compute their respective
+ // cache identifiers, this allows us to do one single cache_get_multiple()
+ // call instead of doing one cache_get() call per block.
+ $cached_blocks = 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) {
+ $cached_blocks = 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 the previously loaded cache entries.
+ if (($cid = _block_get_cache_id($block)) && isset($cached_blocks[$cid])) {
+ $array = $cached_blocks[$cid]->data;
}
else {
$array = module_invoke($block->module, 'block_view', $block->delta);
@@ -1013,13 +1035,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('You can force block caching to be enabled by setting the block_cache_bypass_node_grants variable to TRUE, see the settings.php file.') : NULL,
'#weight' => -1,
);
}
diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php
index 40f552e..d84b460 100644
--- a/sites/default/default.settings.php
+++ b/sites/default/default.settings.php
@@ -433,6 +433,19 @@ ini_set('session.cookie_lifetime', 2000000);
# $conf['js_gzip_compression'] = FALSE;
/**
+ * Block caching:
+ *
+ * Block caching may not compatible with node access modules depending on
+ * how the original block cache policy is defined set by the module that
+ * provides the block. By default, block cache will be disabled when one or
+ * more modules implement the hook_node_grant() hook. If you consider block
+ * caching to be safe on your site, you can bypass this restriction and force
+ * block caching to the default policy (per block setting) by setting the
+ * following variable to TRUE.
+ */
+# $conf['block_cache_bypass_node_grants'] = TRUE;
+
+/**
* String overrides:
*
* To override specific strings on your site with or without enabling the Locale