You are here

function esi_add_cache_headers in ESI: Edge Side Includes 6.2

2 calls to esi_add_cache_headers()
esi__block_handler in ./esi.module
Menu handler for ESIs
esi__panel_pane_handler in ./esi.module
Menu handler to serve individual panel-panes via ESI.

File

./esi.module, line 440
Adds support for ESI (Edge-Side-Include) integration, allowing blocks to be\ delivered by ESI, with support for per-block cache times.

Code

function esi_add_cache_headers($scope, $max_age) {

  // Nginx follows rfc2616 section 14.9.1 correctly and will not cache if
  // header is set to private. The given Varnish VCL does not follow the RFC,
  // and for ajax we want to use private.
  $user_cache_control_header = variable_get('esi_mode', ESI_MODE) == ESI__CONFIG_SSI ? 'public' : 'private';
  switch ($scope) {

    // Disabled.
    case 0:

    // Do no cache.
    case 1:
      drupal_set_header("Cache-Control: must-revalidate, max-age=0");
      break;

    // Global Scope.
    case 2:

    // Page Scope.
    case 3:
      drupal_set_header("Cache-Control: public, max-age={$max_age}");
      break;

    // User Role.
    case 4:

    // User Role/Page.
    case 5:
      drupal_set_header("Cache-Control: {$user_cache_control_header}, max-age={$max_age}");
      drupal_set_header("X-BLOCK-CACHE: " . BLOCK_CACHE_PER_ROLE);
      break;

    // User ID.
    case 6:

    // User ID/Page.
    case 7:
      drupal_set_header("Cache-Control: {$user_cache_control_header}, max-age={$max_age}");
      drupal_set_header("X-BLOCK-CACHE: " . BLOCK_CACHE_PER_USER);
      break;
  }
}