You are here

function optimizely_refresh_cache in Optimizely 7.2

Same name and namespace in other branches
  1. 7.3 optimizely.admin.inc \optimizely_refresh_cache()

optimizely_refresh_cache()

@parm $path_array - An array of the target paths entries that the cache needs to be cleared. Each entry can also contain wildcards /* or variables "<front>".

3 calls to optimizely_refresh_cache()
optimizely_add_update_form_submit in ./optimizely.admin.inc
Process form submissions from optimizely_add_update_form().
optimizely_ajax_enable in ./optimizely.admin.inc
AJAX callback for click event on project enable checkbox.
optimizely_delete_page_confirm_submit in ./optimizely.admin.inc
Submit function for the confirm deletion form. Delete the entry in the database and return the user to the Project listing page.

File

./optimizely.admin.inc, line 670
Admin page callback for the Optimizely module.

Code

function optimizely_refresh_cache($path_array, $original_path_array = NULL) {

  // Determine protocol
  $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
  $cid_base = $protocol . '://' . $_SERVER['HTTP_HOST'] . '/';

  // If update of project that includes changes to the path, clear cache on all
  // paths to add/remove Optimizely javascript call
  if (isset($original_path_array)) {
    $path_array = array_merge($path_array, $original_path_array);
  }

  // Loop through every path value
  foreach ($path_array as $path_count => $path) {
    $recursive = NULL;

    // Apply to all paths when there's a '*' path entry (default project entry
    // for example) or it's an exclude path entry (don't even try to figure out
    // the paths, just flush all page cache
    if (strpos($path, '*') !== 0) {
      if (strpos($path, '<front>') === 0) {
        $cid = $cid_base . '/' . variable_get('site_frontpage', 'node');
        $recursive = FALSE;
      }
      elseif (strpos($path, '/*') > 0) {
        $cid = $cid_base . substr($path, 0, strlen($path) - 2);
        $recursive = TRUE;
      }
      else {
        $cid = $cid_base . $path;
        $recursive = FALSE;
      }
      cache_clear_all($cid, 'cache_page', $recursive);
    }
    else {
      cache_clear_all('*', 'cache_page', TRUE);
      break;
    }
  }

  // Varnish
  if (module_exists('varnish')) {
    varnish_expire_cache($path_array);
    drupal_set_message(t('Successfully purged cached page from Varnish.'));
  }
  drupal_set_message(t('Page cache has been cleared based on the project path settings.'), 'status');
}