Current state:
Current block caching is limited per https://api.drupal.org/api/drupal/includes%21common.inc/group/block_cach...

Problem/motive:
I am having a need to cache block per IP. So I am proposing altering of drupal_render_cid_parts function $cid_parts array with drupal_alter.

With that you can edit granularity in your custom functions and add cid parts. Like I did here with help of Smart_IP module

define('DRUPAL_CACHE_PER_IP', 0x0005);
/**
 * Implements hook_cid_parts_alter().
 */

function lelo_performance_cid_parts_alter(&$cid_parts, &$granularity){

  if ($granularity & DRUPAL_CACHE_PER_IP) {
    $cid_parts[] = $base_root . request_uri() . $_SESSION['smart_ip']['location']['country_code'];
  }
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Marko B created an issue. See original summary.

Marko B’s picture

Marko B’s picture

FileSize
458 bytes
Marko B’s picture

Issue summary: View changes
Marko B’s picture

I found later that block CID altering is already implemented into core in

function _block_get_cache_id($block)
and drupal_alter('block_cid_parts', $cid_parts, $block);

so this seems obsolete for blocks, maybe some other rare case could get something useful with this altering though.

amit0212’s picture

My guess is that it's to maintain similar behavior as drupal_render_cid_create() (which allows you to pass in arbitrary custom keys but not modify any of the ones set by drupal_render_cid_parts()

Patch

Marko B’s picture

yes.