Set global caching for blocks

Basically it turns on caching per page on blocks.

It works with Drupal's core blocks system and blocks from Context module.

If you wish to use refined settings for block cache, please use the Block Cache Alter module.

Project's page: https://drupal.org/sandbox/marcelovani/1889672

Repository: http://drupalcode.org/sandbox/marcelovani/1889672.git

Comments

PA robot’s picture

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

extremal’s picture

It might be worth checking if the context module is enabled.
Also there were too many brackets in the conditional sentences.

girishmuraly’s picture

Status: Needs review » Needs work

http://ventral.org/pareview/httpgitdrupalorgsandboxmarcelovani1889672git PAReview output is fine. Whilst there is adequate documentation, I think the inline comments in this function are not all necessary, as they state exactly what is readable in the corresponding php lines and those php commands are quite readable themselves.

/**
 * Function _blocks_mass_cache_set_cache().
 * 
 * Helper function to set cache.
 */
function _blocks_mass_cache_set_cache(&$blocks) {
  // Check if drupal's block caching is enabled.
  if (variable_get('block_cache', FALSE)) {
    // Check if blocks simple cache is enabled.
    if (variable_get('blocks_mass_cache_enabled', FALSE)) {
      // Get list of exceptions.
      $exception_list = variable_get('blocks_mass_cache_exception_list', array());

      // Loop through blocks.
      foreach ($blocks as $module => $block) {
        // Check if block is array (drupal's default).
        if (is_array($block)) {
          foreach ($blocks[$module] as $key => $block_content) {
            $bid = $block_content['module'] . '-' . $block_content['delta'];
            // Check if the block is listed in the exception list.
            if ((!isset($exception_list[$bid]) || (isset($exception_list[$bid])) && $exception_list[$bid] == FALSE)) {
              // Set global caching.
              $blocks[$module][$key]['cache'] = DRUPAL_CACHE_PER_PAGE;
            }
          }
        }
        // Check if block is object (context's module).
        if (is_object($block)) {
          $bid = $block->module . '-' . $block->delta;
          // Check if the block is listed in the exception list.
          if ((!isset($exception_list[$bid]) || (isset($exception_list[$bid])) && $exception_list[$bid] == FALSE)) {
            // Set global caching.
            $blocks[$bid]->cache = DRUPAL_CACHE_PER_PAGE;
          }
        }
      }
    }
  }
}
x7ian’s picture

1. Need to use t() function on Lines 32 at blocks_mass_cache.admin.inc and 14 on blocks_mass_cache.module

2. Some information is missing at the README.txt file. At least include the information at the project in your sandbox.

Contratulations,
Nice module!

marcelovani’s picture

Thanks for the reviews
@extremal I have simplified the logic and fixed the brackets http://drupalcode.org/sandbox/marcelovani/1889672.git/commitdiff/93b4769...

@x7ian I have added the t() function on all titles and descriptions. Will add more info to the README.txt soon

marcelovani’s picture

There is a bug on Context module, which is throwing away all the cache info settings for the blocks.
This is causing Blocks Mass Cache to fail to work with Context until they fix it.
This is the line that is causing the problem
unset($block_info["{$row->module}-{$row->delta}"]->cache);
see https://drupal.org/node/2037793

extremal’s picture

@marcelovani, perhaps you could simplify this:

if (empty($exception_list[$bid]) || empty($exception_list[$bid])) {

to this

if (empty($exception_list[$bid])) {

marcelovani’s picture

@extremal Done, thanks for spotting that

marcelovani’s picture

Status: Needs work » Needs review

They applied my patch on Context and the bug has been fixed, use Context version 7.x-3.0-beta7 or higher
I have updated the README file and the project info

theapi’s picture

Status: Needs review » Reviewed & tested by the community

Handy

kscheirer’s picture

Status: Reviewed & tested by the community » Fixed

Can you move the blocks_mass_cache_init() down into blocks_mass_cache_preprocess_block()? Checking on hook_init happens with every page request in Drupal.
You have a couple of style issues reported here: http://pareview.sh/pareview/httpgitdrupalorgsandboxmarcelovani1889672git.
I think you can use system_settings_form() at the end of blocks_mass_cache_admin_settings_form() and then you don't need the submit function to save all those variables.

Not blocking issues though, looks like a nice module.

Thanks for your contribution, marcelovani!

I updated your account to let you promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and get involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

----
Top Shelf Modules - Crafted, Curated, Contributed.

marcelovani’s picture

Status: Fixed » Closed (fixed)

Hi kscheirer

Thanks a lot for doing this.

I have implemented the changes you suggested, apart from the one about the configuration page, which I will be doing soon.

Keep up the good work.

Marcelo

marcelovani’s picture

Issue summary: View changes

Updating description