I understand that certain block caching options can be combined. What does it mean if I set the caching option of a block defined in code to DRUPAL_CACHE_PER_ROLE|DRUPAL_CACHE_PER_PAGE?

I am confused by the OR bitwise operator. Does this mean that the block will not only be cached by page, but also by role? For example, if User role A visits the same page as User role B, they will each see different cached versions of the block despite being on the same page?

1 Answer 1


According to the documentation:

Page and user settings can be combined with a bitwise-binary or operator; for example, DRUPAL_CACHE_PER_ROLE | DRUPAL_CACHE_PER_PAGE means that the block can change depending on the user role or page it is on.

In other words: When the block is cached, information about the user role and page are stored with it. The cached version is served only in situations where both the current user role and the current page match those of the cached block.

A good example in Drupal 7 core is the Author Information block (see block info, block view). It must vary by page, because every page can have a different author, and it must vary by role, because not every role may have permissions to view the author information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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