WordPress at a glance
function is not described

wp_cache_serve_cache_file() WPSCache 1.0

No Hooks.

Return

Null. Nothing.

Usage

wp_cache_serve_cache_file();

Code of wp_cache_serve_cache_file() WPSCache 1.7.1

<?php
function wp_cache_serve_cache_file() {
	global $key, $blogcacheid, $wp_cache_request_uri, $file_prefix, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname, $wp_cache_gzip_encoding, $meta;
	global $cache_compression, $wp_cache_slash_check, $wp_supercache_304, $wp_cache_home_path, $wp_cache_no_cache_for_get;
	global $wp_cache_disable_utf8, $wp_cache_mfunc_enabled, $wpsc_served_header;

	if ( wpsc_is_backend() ) {
		wp_cache_debug( 'Not serving wp-admin requests.', 5 );
		return false;
	}

	if ( $wp_cache_no_cache_for_get && false == empty( $_GET ) ) {
		wp_cache_debug( 'Non empty GET request. Caching disabled on settings page. ' . wpsc_dump_get_request(), 1 );
		return false;
	}

	if ( defined( 'WPSC_SERVE_DISABLED' ) ) {
		wp_cache_debug( 'wp_cache_serve_cache_file: WPSC_SERVE_DISABLED defined. Not serving cached files.' );
		return false;
	}

	extract( wp_super_cache_init() ); // $key, $cache_filename, $meta_file, $cache_file, $meta_pathname

	if (
		! defined( 'WPSC_SUPERCACHE_ONLY' ) &&
		(
			( $cache_file && file_exists( $cache_file ) ) ||
			file_exists( get_current_url_supercache_dir() . 'meta-' . $cache_filename )
		)
	) {
		if ( file_exists( get_current_url_supercache_dir() . 'meta-' . $cache_filename ) ) {
			$cache_file = get_current_url_supercache_dir() . $cache_filename;
			$meta_pathname = get_current_url_supercache_dir() . 'meta-' . $cache_filename;
		} elseif ( !file_exists( $cache_file ) ) {
			wp_cache_debug( 'wp_cache_serve_cache_file: found cache file but then it disappeared!' );
			return false;
		}

		wp_cache_debug( "wp-cache file exists: $cache_file", 5 );
		if ( !( $meta = json_decode( wp_cache_get_legacy_cache( $meta_pathname ), true ) ) ) {
			wp_cache_debug( "couldn't load wp-cache meta file", 5 );
			return true;
		}
		if ( is_array( $meta ) == false ) {
			wp_cache_debug( "meta array corrupt, deleting $meta_pathname and $cache_file", 1 );
			@unlink( $meta_pathname );
			@unlink( $cache_file );
			return true;
		}
	} else { // no $cache_file
		global $wpsc_save_headers;
		global $cache_max_time;
		// last chance, check if a supercache file exists. Just in case .htaccess rules don't work on this host
		$filename = supercache_filename();
		$file = get_current_url_supercache_dir() . $filename;
		if ( false == file_exists( $file ) ) {
			wp_cache_debug( "No Super Cache file found for current URL: $file" );
			return false;
		} elseif ( false == empty( $_GET ) ) {
			wp_cache_debug( 'GET array not empty. Cannot serve a supercache file. ' . wpsc_dump_get_request() );
			return false;
		} elseif ( wp_cache_get_cookies_values() != '' ) {
			wp_cache_debug( 'Cookies found. Cannot serve a supercache file. ' . wp_cache_get_cookies_values() );
			return false;
		} elseif ( isset( $wpsc_save_headers ) && $wpsc_save_headers ) {
			wp_cache_debug( 'Saving headers. Cannot serve a supercache file.' );
			return false;
		} elseif ( $cache_max_time > 0 && ( filemtime( $file ) + $cache_max_time ) < time() ) {
			wp_cache_debug( sprintf( "Cache has expired and is older than %d seconds old.", $cache_max_time ) );
			return false;
		}

		if ( isset( $wp_cache_mfunc_enabled ) == false )
			$wp_cache_mfunc_enabled = 0;

		if ( false == isset( $wp_cache_home_path ) )
			$wp_cache_home_path = '/';

		// make sure ending slashes are ok
		if ( $wp_cache_request_uri == $wp_cache_home_path || ( $wp_cache_slash_check && substr( $wp_cache_request_uri, -1 ) == '/' ) || ( $wp_cache_slash_check == 0 && substr( $wp_cache_request_uri, -1 ) != '/' ) ) {

			if ( $wp_cache_mfunc_enabled == 0 ) {
				// get data from file
				if ( $wp_cache_gzip_encoding ) {
					if ( file_exists( $file . '.gz' ) ) {
						$cachefiledata = file_get_contents( $file . '.gz' );
						wp_cache_debug( "Fetched gzip static page data from supercache file using PHP. File: $file.gz" );
					} else {
						$cachefiledata = gzencode( file_get_contents( $file ), 6, FORCE_GZIP );
						wp_cache_debug( "Fetched static page data from supercache file using PHP and gzipped it. File: $file" );
					}
				} else {
					$cachefiledata = file_get_contents( $file );
					wp_cache_debug( "Fetched static page data from supercache file using PHP. File: $file" );
				}
			} else {
				// get dynamic data from filtered file
				$cachefiledata = do_cacheaction( 'wpsc_cachedata', file_get_contents( $file ) );
				if ( $wp_cache_gzip_encoding ) {
					$cachefiledata = gzencode( $cachefiledata, 6, FORCE_GZIP );
					wp_cache_debug( "Fetched dynamic page data from supercache file using PHP and gzipped it. File: $file" );
				} else {
					wp_cache_debug( "Fetched dynamic page data from supercache file using PHP. File: $file" );
				}
			}

			if ( isset( $wp_cache_disable_utf8 ) == false || $wp_cache_disable_utf8 == 0 )
				header( "Content-type: text/html; charset=UTF-8" );

			if ( defined( 'WPSC_VARY_HEADER' ) ) {
				if ( WPSC_VARY_HEADER != '' ) {
					header( "Vary: " . WPSC_VARY_HEADER );
				}
			} else {
				header( "Vary: Accept-Encoding, Cookie" );
			}
			if ( defined( 'WPSC_CACHE_CONTROL_HEADER' ) ) {
				if ( WPSC_CACHE_CONTROL_HEADER != '' ) {
					header( "Cache-Control: " . WPSC_CACHE_CONTROL_HEADER );
				}
			} else {
				header( "Cache-Control: max-age=3, must-revalidate" );
			}
			$size = function_exists( 'mb_strlen' ) ? mb_strlen( $cachefiledata, '8bit' ) : strlen( $cachefiledata );
			if ( $wp_cache_gzip_encoding ) {
				if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
					header( "X-WP-Super-Cache: Served supercache gzip file from PHP" );
				}
				header( 'Content-Encoding: ' . $wp_cache_gzip_encoding );
				header( 'Content-Length: ' . $size );
			} elseif ( $wp_supercache_304 ) {
				if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
					header( "X-WP-Super-Cache: Served supercache 304 file from PHP" );
				}
				header( 'Content-Length: ' . $size );
			} else {
				if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
					header( "X-WP-Super-Cache: Served supercache file from PHP" );
				}
			}

			// don't try to match modified dates if using dynamic code.
			if ( $wp_cache_mfunc_enabled == 0 && $wp_supercache_304 ) {
				$headers         = apache_request_headers();
				$remote_mod_time = isset ( $headers['If-Modified-Since'] ) ? $headers['If-Modified-Since'] : null;

				if ( is_null( $remote_mod_time ) && isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
					$remote_mod_time = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
				}

				$local_mod_time = gmdate("D, d M Y H:i:s",filemtime( $file )).' GMT';
				if ( ! is_null( $remote_mod_time ) && $remote_mod_time == $local_mod_time ) {
					header( $_SERVER[ 'SERVER_PROTOCOL' ] . " 304 Not Modified" );
					exit();
				}
				header( 'Last-Modified: ' . $local_mod_time );
			}
			echo $cachefiledata;
			exit();
		} else {
			wp_cache_debug( 'No wp-cache file exists. Must generate a new one.' );
			return false;
		}
	}

	$cache_file = do_cacheaction( 'wp_cache_served_cache_file', $cache_file );
	// Sometimes the gzip headers are lost. Make sure html returned isn't compressed!
	if ( $cache_compression && $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $meta[ 'headers' ] ) ) {
		$ungzip = true;
		wp_cache_debug( 'GZIP headers not found. Force uncompressed output.', 1 );
	} else {
		$ungzip = false;
	}
	foreach ( $meta[ 'headers' ] as $t => $header) {
		// godaddy fix, via http://blog.gneu.org/2008/05/wp-supercache-on-godaddy/ and http://www.littleredrails.com/blog/2007/09/08/using-wp-cache-on-godaddy-500-error/
		if ( strpos( $header, 'Last-Modified:' ) === false ) {
			header( $header );
		}
	}
	if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
		header( 'X-WP-Super-Cache: Served WPCache cache file' );
	}
	if ( isset( $meta[ 'dynamic' ] ) ) {
		wp_cache_debug( 'Serving wp-cache dynamic file', 5 );
		if ( $ungzip ) {
			// attempt to uncompress the cached file just in case it's gzipped
			$cache = wp_cache_get_legacy_cache( $cache_file );
			$uncompressed = @gzuncompress( $cache );
			if ( $uncompressed ) {
				wp_cache_debug( 'Uncompressed gzipped cache file from wp-cache', 1 );
				unset( $cache );
				echo do_cacheaction( 'wpsc_cachedata', $uncompressed );
			} else {
				echo do_cacheaction( 'wpsc_cachedata', $cache );
			}
		} else {
			echo do_cacheaction( 'wpsc_cachedata', wp_cache_get_legacy_cache( $cache_file ) );
		}
	} else {
		wp_cache_debug( 'Serving wp-cache static file', 5 );
		if ( $ungzip ) {
			$cache = wp_cache_get_legacy_cache( $cache_file );
			$uncompressed = gzuncompress( $cache );
			if ( $uncompressed ) {
				wp_cache_debug( 'Uncompressed gzipped cache file from wp-cache', 1 );
				echo $uncompressed;
			} else {
				wp_cache_debug( 'Compressed gzipped cache file from wp-cache', 1 );
				echo $cache;
			}
		} else {
			wp_cache_debug( 'Getting legacy cache file ' . $cache_file, 1 );
			echo( wp_cache_get_legacy_cache( $cache_file ) );
		}
	}
	wp_cache_debug( 'exit request', 5 );
	die();
}