If a block is set to use DRUPAL_CACHE_PER_USER for caching, will the block be unique for each anonymous user, or the same for all anonymous users?

For reference from API docs: hook_block_info DRUPAL_CACHE_PER_USER

Looking at includes/common.inc source it appears to be based on uid, so I'd assume it would use the same block for all anonymous users (uid = 0), but wanted to double-check in case I could use this instead of DRUPAL_NO_CACHE (doing geolocation-driven results in the block).

elseif ($granularity & DRUPAL_CACHE_PER_USER) {
  $cid_parts[] = "u.$user->uid";

(lines 6084-6086)


Yes. If a user is not logged in then uid is 0. So all anon users share the same user id.

I guess you will have to do your own caching, e.g. based on the IP address.

  • Thanks for the confirmation. Yes, the IP address approach is what I'm pursuing now. Only trouble with that is if someone is VPN'd into a network while traveling remotely, but fairly edge case I hope. – Joshua Stewardson Jul 16 '12 at 11:34

There is a option to "Cache pages for anonymous users" in Drupal 7.

Admin->Configuration->Performance Look in the Caching Group just below the Clear Cache button.

  • The OP is aware of that. He is asking if blocks can be cached uniquely for each anonymous user. – user7667 Jul 16 '12 at 18:47

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.