Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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'];
}
}
Comment | File | Size | Author |
---|---|---|---|
#3 | alter_cid_parts-2844524-3.patch | 458 bytes | Marko B |
Comments
Comment #2
Marko B CreditAttribution: Marko B commentedComment #3
Marko B CreditAttribution: Marko B commentedComment #4
Marko B CreditAttribution: Marko B commentedComment #5
Marko B CreditAttribution: Marko B commentedI 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.
Comment #6
amit0212 CreditAttribution: amit0212 as a volunteer and commentedMy 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
Comment #7
Marko B CreditAttribution: Marko B commentedyes.