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 :) ) Sincerely, Fredrik Kilander Maintainer of yr_verdata.module
Hi Fredrik - I think you may have been testing as user 1. I started testing your problem and noticed the same thing and started debugging and then noticed this code: function _block_get_cache_id($block) { global $user; // User 1 being out of the regular 'roles define permissions' schema, // it brings too many chances of having unwanted output get in the cache // and later be served to other users. We therefore exclude user 1 from // block caching. My testing (after I logged in as a different user) did show caching work correctly, at least in casual testing. As a result of your note I've added a timestamp into one of the blocks provided by the Block Example module, part of the Examples project ( http://drupal.org/project/examples) so that one can easily explore whether caching is happening or not. When http://drupal.org/node/995316 goes in (maybe tonight) it will make an easier way to explore block caching. -Randy On Tue, Dec 7, 2010 at 4:25 PM, Fredrik Sandve Kilander < fredrik.kilander@gmail.com> wrote:
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 :) )
Sincerely, Fredrik Kilander Maintainer of yr_verdata.module
-- Randy Fay Drupal Module and Site Development randy@randyfay.com +1 970.462.7450
participants (2)
-
Fredrik Sandve Kilander -
Randy Fay