function _blockcache_alter_get_cache_id in Block Cache Alter 6
Get cid for a block.
1 call to _blockcache_alter_get_cache_id()
- blockcache_alter_block_view in ./
blockcache_alter.module - View a cached block using hook_block(). If the block is not cached or the cache is stale, get the info and stick it back into the cache.
File
- ./
blockcache_alter.module, line 494 - Block Cache alter.
Code
function _blockcache_alter_get_cache_id($module, $delta) {
global $theme, $base_root, $user;
static $block_cache = array();
if (!isset($block_cache[$module][$delta])) {
$result = db_query("SELECT module, delta, cache FROM {blocks} WHERE theme = '%s'", $theme);
while ($row = db_fetch_object($result)) {
$block_cache[$row->module][$row->delta] = $row->cache;
}
}
$block = new stdClass();
$block->cache = $block_cache[$module][$delta];
// User 1 being out of the regular 'roles define permissions' schema,
// it brings too many chances of having unwanted output get in the cache
// and later be served to other users. We therefore exclude user 1 from
// block caching.
if (variable_get('block_cache', 0) && $block->cache != BLOCK_NO_CACHE && $user->uid != 1) {
$cid_parts = array();
// Start with common sub-patterns: block identification, theme, language.
$cid_parts[] = $module;
$cid_parts[] = $delta;
$cid_parts[] = $theme;
if (module_exists('locale')) {
global $language;
$cid_parts[] = $language->language;
}
// 'PER_ROLE' and 'PER_USER' are mutually exclusive. 'PER_USER' can be a
// resource drag for sites with many users, so when a module is being
// equivocal, we favor the less expensive 'PER_ROLE' pattern.
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);
}
}