[development] Block caching in D7

Fredrik Sandve Kilander fredrik.kilander at gmail.com
Wed Dec 8 00:25:25 UTC 2010

Hello. I am the maintainer of the yr_verdata module, and as I am trying to finish up updating my module for D7, I am having trouble understanding how block caching works. On my development site, I have enabled caching, and in hook_block_info() i have specified caching as per the example at api.drupal.org:

  $blocks['yr_verdata_block'] = array(
    'info' => t('Yr weather forecast for all locations'),
    'cache' => DRUPAL_CACHE_PER_ROLE, // I have tried with per page and global as well.

This does not cache the block. If I set caching in the render array that's passed to $block['content'] in hook_block_view(), the caching works, but there are two things i wonder:
1. Is that the correct way to cache blocks?
2. Using render arrays with the '#cache' element in hook_block_view() works independently of whether or not I 'enable' caching in hook_block_view(). Why is this?

What's the best practice for going about this?
Source code can be seen at drupalcode.org: http://bit.ly/g586j6
Lines: 185 (hook_block_info), 209 (hook_block_view). Theme function for the block is at 477, which gets its array of stuff from line 327 (the function called there, yr_verdata_generate_forecastbox(), starts at 349).
 (if you find any other stuff in my code to bash at, feel free :) )

Fredrik Kilander
Maintainer of yr_verdata.module

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20101208/d814ccf8/attachment.html 

More information about the development mailing list