You are here

function admin_block_get_cache_id in Admin 6.2

Implement our own simplified block caching. Because the Drupal core block caching system is so conservative (e.g. disabled when *any* node_access module is enabled), we roll our own solution here. Note that except for the introduction of a user 1 specific cache, the cid generated by this function is compatible with those in Drupal core.

1 call to admin_block_get_cache_id()
admin_set_admin_blocks in ./admin.module
Set static cache for blocks enabled for the admin toolbar.

File

./admin.module, line 104

Code

function admin_block_get_cache_id($block) {
  global $theme, $base_root, $user;
  if ($block->cache != BLOCK_NO_CACHE) {
    $cid_parts = array();

    // Start with common sub-patterns: block identification, theme, language.
    $cid_parts[] = $block->module;
    $cid_parts[] = $block->delta;
    $cid_parts[] = $theme;
    if (module_exists('locale')) {
      global $language;
      $cid_parts[] = $language->language;
    }

    // In addition to the Drupal core pattern, allow caching separately for u1.
    if ($user->uid == 1) {
      $cid_parts[] = "u.{$user->uid}";
    }
    else {
      if ($block->cache & BLOCK_CACHE_PER_ROLE) {
        $cid_parts[] = 'r.' . implode(',', array_keys($user->roles));
      }
      elseif ($block->cache & BLOCK_CACHE_PER_USER) {
        $cid_parts[] = "u.{$user->uid}";
      }
    }
    if ($block->cache & BLOCK_CACHE_PER_PAGE) {
      $cid_parts[] = $base_root . request_uri();
    }
    return implode(':', $cid_parts);
  }
}