Skip to content
Snippets Groups Projects
Commit ee41b9c0 authored by Erick Hitter's avatar Erick Hitter
Browse files

Add static caching to URL building method to reduce burden of calling it multiple times.

Fixes #4.
parent 147b2c9f
No related branches found
No related tags found
No related merge requests found
...@@ -132,18 +132,22 @@ function redis_page_cache_handle_cdn_remote_addressing() { ...@@ -132,18 +132,22 @@ function redis_page_cache_handle_cdn_remote_addressing() {
* @return string * @return string
*/ */
function redis_page_cache_get_clean_url() { function redis_page_cache_get_clean_url() {
$proto = 'http'; static $url;
if ( isset( $_SERVER['HTTPS'] ) && ( 'on' === strtolower( $_SERVER['HTTPS'] ) || '1' === $_SERVER['HTTPS'] ) ) {
$proto .= 's'; if ( ! $url ) {
} elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { $proto = 'http';
$proto .= 's'; if ( isset( $_SERVER['HTTPS'] ) && ( 'on' === strtolower( $_SERVER['HTTPS'] ) || '1' === $_SERVER['HTTPS'] ) ) {
} $proto .= 's';
} elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
$proto .= 's';
}
$url = parse_url( $proto . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); $url = parse_url( $proto . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
if ( $url ) { if ( $url ) {
$url = $url['scheme'] . '://' . $url['host'] . $url['path']; $url = $url['scheme'] . '://' . $url['host'] . $url['path'];
} else { } else {
$url = microtime(); $url = microtime();
}
} }
return $url; return $url;
...@@ -378,7 +382,8 @@ try { ...@@ -378,7 +382,8 @@ try {
*/ */
if ( $redis_page_cache_config['debug'] ) { if ( $redis_page_cache_config['debug'] ) {
$redis_page_cache_config['debug_messages'] .= "<!-- Redis Page Cache by Erick Hitter (http://eth.pw/rpc). Page generated in " . redis_page_cache_time_elapsed( $start, microtime() ) . " seconds. -->\n"; $redis_page_cache_config['debug_messages'] .= "<!-- Redis Page Cache by Erick Hitter (http://eth.pw/rpc). Page generated in " . redis_page_cache_time_elapsed( $start, microtime() ) . " seconds. -->\n";
$redis_page_cache_config['debug_messages'] .= "<!-- Cache key: " . $redis_page_cache_config['redis_key'] . "-->\n"; $redis_page_cache_config['debug_messages'] .= "<!-- Cache key: " . $redis_page_cache_config['redis_key'] . " -->\n";
$redis_page_cache_config['debug_messages'] .= "<!-- Cached URL: " . redis_page_cache_get_clean_url() . " -->\n";
if ( isset( $redis_page_cache_config['unlimited'] ) && $redis_page_cache_config['unlimited'] ) { if ( isset( $redis_page_cache_config['unlimited'] ) && $redis_page_cache_config['unlimited'] ) {
$cache_duration = 'infinite'; $cache_duration = 'infinite';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment