I have a block with the cache setting DRUPAL_CACHE_PER_USER.

I want to clear the cache when a user performs a specific action. I want to clear the cached block only for the acting user, keeping the block cache for all other users.

How can I do that in Drupal 7?


This data is stored in the block_cache bin under the cid format:


Knowing that, you can build some wrapper function for cache_clear_all() that will delete any arbitrary UID's cached block:

function clear_user_block_cache($uid, $module = 'MYMODULE', $block = 'MYBLOCK', $theme = 'MYTHEME') {

You can invoke this function call whenever the user takes the relevant action.

| improve this answer | |

If you get an exception on cache_clear_all(), make sure you add the table name as second parameter. E.g: cache_clear_all('yourcidstring', 'fromThisDbTable');

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.