Last active
April 5, 2017 18:40
-
-
Save pbuyle/c2cf59a22e9cd173f4aafa8ae7a0d273 to your computer and use it in GitHub Desktop.
Revisions
-
pbuyle revised this gist
Dec 9, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,8 @@ <?php /** * Implements hook_init(). */ function MODULE_init() { // Add Surrogate-Key headers based on path segments. // E.g. if the current path is product/some-category/product-name -
pbuyle revised this gist
Dec 9, 2016 . No changes.There are no files selected for viewing
-
pbuyle revised this gist
Dec 9, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,6 +33,7 @@ function MODULE_expire_cache($urls, $wildcards, $object_type, $object) { return; } if (!empty($urls) && function_exists('pantheon_clear_edge_paths')) { $urls = array_map(function($url) {return "/$url";}, $urls); pantheon_clear_edge_paths($urls); } // For wildcards, we use the Surrogate-Key purging functionality. -
pbuyle revised this gist
Dec 9, 2016 . 1 changed file with 35 additions and 29 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,40 +1,46 @@ <?php function MODULE_init() { // Add Surrogate-Key headers based on path segments. // E.g. if the current path is product/some-category/product-name // we should end up with the following Surrogate-Keys: // product product/some-category product/some-category/product-name $path_segments = explode('/', drupal_get_path_alias()); $surrogate_keys = array(); $full_url = ''; foreach ($path_segments as $segment) { if (empty($surrogate_keys)) { $full_url = $segment; } else { $full_url .= '/' . $segment; } $surrogate_keys[] = $full_url; } drupal_add_http_header('Surrogate-Key', implode(' ', $surrogate_keys)); } /** * Implements hook_expire_cache(). * * Provides integration of Pantheon with the Cache Expiration (expire) module. * * Be sure to uncheck "Include base URL in expires" in Cache Expiration settings. */ function MODULE_expire_cache($urls, $wildcards, $object_type, $object) { if (variable_get('expire_include_base_url', EXPIRE_INCLUDE_BASE_URL)) { return; } if (!empty($urls) && function_exists('pantheon_clear_edge_paths')) { pantheon_clear_edge_paths($urls); } // For wildcards, we use the Surrogate-Key purging functionality. // Surrogate-Key headers are set in the response based on the // url path segments. // @See MODULE_init(). $paths = array_keys($wildcards, TRUE); if (!empty($paths) && function_exists('pantheon_clear_edge_keys')) { pantheon_clear_edge_keys($paths); } } -
pbuyle revised this gist
Dec 9, 2016 . No changes.There are no files selected for viewing
-
pbuyle created this gist
Dec 9, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ <?php /** * Implements hook_expire_cache(). * * Provides integration of Pantheon with the Cache Expiration (expire) module. * * Will only works for relative URLs in $urls. Be sure to uncheck "Include base URL in expires" in Cache Expiration * settings. */ function MODULE_expire_cache($urls, $wildcards, $object_type, $object) { if (defined('PANTHEON_ENVIRONMENT') && defined('PANTHEON_SITE_NAME')) { foreach ($urls as $original_url) { $options = array( 'method' => 'PURGE', // We just want to execute the queue but not wait. 'blocking' => FALSE, ); // Build the full purged URL $url = url($original_url, array('absolute' => TRUE, 'alias' => TRUE)); // Extract the host from that URL, and set it in the Host header. $parsed_url = @parse_url($url); $default_port = $parsed_url['scheme'] == 'https' ? 443 : 80; $port = isset($parsed_url['port']) ? $parsed_url['port'] : $default_port; $options['headers']['Host'] = $parsed_url['host'] . ($port != $default_port ? ':' . $port : ''); // Build the URL of the purge endpoint $purge_endpoint = $parsed_url['scheme'] . '://' . PANTHEON_ENVIRONMENT . '-' . PANTHEON_SITE_NAME . '.pantheonsite.io:' . $default_port; $url = url($original_url, array( 'absolute' => TRUE, 'alias' => TRUE, 'base_url' => $purge_endpoint )); httprl_request(array($url), $options); } httprl_send_request(); } }