You are here

public static function ExpireAPI::executeExpiration in Cache Expiration 7.2

Executes internal or external cache expiration.

Parameters

$urls: List of internal or external urls that should be expired.

$object_type: Name of object type ('node', 'comment', 'user', etc).

$object: Object (node, comment, user, etc) for which expiration is executes.

$absolute_urls_passed: Indicates whether absolute URLs or internal paths were passed.

10 calls to ExpireAPI::executeExpiration()
drush_expire_absolute_url in ./expire.drush.inc
Callback for expire-url drush command.
drush_expire_internal_path in ./expire.drush.inc
Callback for expire-path drush command.
ExpireComment::expire in includes/expire.comment.inc
Executes expiration actions for comment.
ExpireFile::expire in includes/expire.file.inc
Executes expiration actions for file.
ExpireMenuLink::expire in includes/expire.menu_link.inc
Executes expiration actions for menu link.

... See full list

File

includes/expire.api.inc, line 25
Provides internal API for page cache flushes.

Class

ExpireAPI
@file Provides internal API for page cache flushes.

Code

public static function executeExpiration($urls, $object_type = '', $object = NULL, $absolute_urls_passed = FALSE) {

  // Allow other modules to modify the list prior to expiring.
  drupal_alter('expire_cache', $urls, $object_type, $object, $absolute_urls_passed);

  // Nothing to expire, so exit.
  if (empty($urls)) {
    return;
  }

  // Check if base urls should be included.
  $include_base_url = variable_get('expire_include_base_url', EXPIRE_INCLUDE_BASE_URL);

  // Absolute urls may be passed from drush command or from rules action.
  if ($absolute_urls_passed) {

    // If was passed array with absolute URLs, we need to add to them
    // internal path first, because some external cache tools (like Varnish)
    // works only with internal paths.
    $urls = self::addInternalPaths($urls);

    // If base url should not be include (for example, for Varnish or Acquia Purge),
    // then remove it from values.
    if (!$include_base_url) {
      $urls = drupal_map_assoc(array_keys($urls));
    }

    // We not allow using wildcards for absolute urls.
    $wildcards = array_fill_keys(array_keys($urls), FALSE);
  }
  else {

    // Define a language code. It will be used to define path aliases.
    $langcode = NULL;
    if (!empty($object_type) && !empty($object)) {
      if (function_exists('entity_language')) {
        $langcode = entity_language($object_type, $object);
      }
      else {
        $info = entity_get_info($object_type);
        if (isset($info['language callback']) && function_exists($info['language callback'])) {
          $langcode = $info['language callback']($object_type, $object);
        }
        elseif (!empty($info['entity keys']['language']) && isset($object->{$info['entity keys']['language']})) {
          $langcode = $object->{$info['entity keys']['language']};
        }
        else {
          $langcode = NULL;
        }
      }
    }

    // Get a language of current object (if exists). We need to respect cases
    // when entities having one site language has been expired from another
    // site locale. For this purpose we always have to pass a proper language
    // key/object to get a correct URL of entity's language.
    if ($langcode == LANGUAGE_NONE) {
      $language = language_default();
      $langcode = $language->language;
    }
    else {
      $languages = language_list();
      $language = isset($languages[$langcode]) ? $languages[$langcode] : NULL;
    }

    // Adds paths aliases, defines wildcards, etc.
    list($urls, $wildcards) = self::processInternalPaths($urls, $langcode);

    // If base site url should be included, then simply add it to the internal paths.
    if ($include_base_url) {
      foreach ($urls as $raw_url => $url) {
        $urls[$raw_url] = url($url['path'], array(
          'absolute' => TRUE,
          'alias' => TRUE,
          'language' => $language,
          'query' => $url['query'],
        ));
      }
    }
  }

  // Latest possibility to change urls that should be expired.
  drupal_alter('expire_urls', $urls, $object_type, $object);

  // Probably during alteration all urls were deleted. In this case
  // we should stop any further expiration.
  if (empty($urls)) {
    return;
  }

  // Write some debug information.
  self::debugLog($urls, $wildcards, $object_type);

  // Execute internal or external expiration.
  $status = variable_get('expire_status', EXPIRE_STATUS_DISABLED);
  if ($status == EXPIRE_STATUS_ENABLED_INTERNAL) {
    self::executeInternalExpiration($urls, $wildcards);
  }
  elseif ($status == EXPIRE_STATUS_ENABLED_EXTERNAL) {
    self::executeExternalExpiration($urls, $wildcards, $object_type, $object);
  }
}