You are here

function esi_max_age_options in ESI: Edge Side Includes 7.3

Same name and namespace in other branches
  1. 6.2 esi.inc \esi_max_age_options()

Get a list of possible max age (ttl) choices.

Parameters

optional Int $current_max_age: The defined max age might not amongst the pre-defined options. Adding the current max age as a parameter allows it to be added to the list of options, ensuring the current configuration doesn't get overridden.

Return value

Array Array of potential max-age choices. The key is the TTL (in seconds) and the value is the human-readable description of that TTL.

3 calls to esi_max_age_options()
esi_admin_configuration_form in ./esi.admin.inc
Menu handler to display the configuration form.
esi_block_form_block_admin_configure_alter in modules/esi_block/esi_block.module
Implements hook_form_FORM_ID_alter(). for block_admin_configure Add ESI-configuration options to the block-config pages.
esi_panels_esi_cache_settings_form in modules/esi_panels/plugins/cache/esi.inc
Admin-settings form for configuring the ESI cache on panel panes.

File

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

Code

function esi_max_age_options($current_max_age = NULL) {
  if (is_null($current_max_age)) {
    $current_max_age = variable_get('esi_default_ttl', ESI_DEFAULT_TTL);
  }
  $options = drupal_map_assoc(array(
    0,
    5,
    15,
    30,
    60,
    120,
    180,
    240,
    300,
    600,
    900,
    1200,
    1800,
    3600,
    7200,
    14400,
    28800,
    43200,
    64800,
    86400,
    86400 * 2,
    86400 * 3,
    86400 * 4,
    86400 * 5,
    86400 * 6,
    86400 * 7,
  ), 'format_interval');

  // If the given max age isn't one of our options, add the current max age as a custom option.
  if (!isset($options[$current_max_age])) {
    $options[$current_max_age] = t('Custom: @time', array(
      '@time' => format_interval($current_max_age),
    ), array(
      'context' => 'Cache Duration',
    ));
    ksort($options);
  }
  $options[0] = '<' . t('none', array(), array(
    'context' => 'Cache Duration',
  )) . '>';
  return $options;
}