Hi Folks,

The problem i am having is all of blocks are being cached. How do I fix this.

Please help me on how to instruct drupal to cache specific blocks data.... Some of my blocks have dynamic data, and I want some of them to be cached...

Will the use of constants work like blocks[0]['cache'] = BLOCK_NO_CACHE / BLOCK_CACHE_GLOBAL

Comments

SilviuChingaru’s picture

+1 to this....

--
Works at Magazinul Cu Scule .ro

alexbk66-’s picture

I do it in sql, not sure if it's the best, but it works.

update blocks
set cache=1 where module='menu_block'

The number is a sum of constants defined in block.module, i.e. for 'per user'+'per page' set to 6.

jaypan’s picture

hook_block() gives a bunch of different caching options:

BLOCK_CACHE_PER_ROLE (default): The block can change depending on the roles the user viewing the page belongs to.
BLOCK_CACHE_PER_USER: The block can change depending on the user viewing the page. This setting can be resource-consuming for sites with large number of users, and should only be used when BLOCK_CACHE_PER_ROLE is not sufficient.
BLOCK_CACHE_PER_PAGE: The block can change depending on the page being viewed.
BLOCK_CACHE_GLOBAL: The block is the same for every user on every page where it is visible.
BLOCK_NO_CACHE: The block should not get cached.

Pick the one that works best for you.

Contact me to contract me for D7 -> D10/11 migrations.

alexbk66-’s picture

Yes, it didn't work fro me because I put it under wrong 'case' statement.
It should be in 'list':

  switch ($op) {
    case 'list':
     $blocks[0]['info'] = t('Hobby Block');
     $blocks[0]['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_USER;
alexbk66-’s picture

Also I found a Block Cache Alter module.
[EDIT]
This module does it 'Drupal' way.