$v) { /* check for any matches to user-added cookies to no-cache */ foreach ( $nocache_cookies as $nocache_cookie ) { if( strpos( $n, $nocache_cookie ) === 0 ) { __wp_ffpc_debug__ ( "Cookie exception matched: {$n}, skipping"); return false; } } } } } /* no cache for excluded URL patterns */ if ( isset($wp_ffpc_config['nocache_url']) && trim($wp_ffpc_config['nocache_url']) ) { $pattern = sprintf('#%s#', trim($wp_ffpc_config['nocache_url'])); if ( preg_match($pattern, $wp_ffpc_uri) ) { __wp_ffpc_debug__ ( "Cache exception based on URL regex pattern matched, skipping"); return false; } } /* canonical redirect storage */ $wp_ffpc_redirect = null; /* fires up the backend storage array with current config */ include_once ('wp-ffpc-backend.php'); $backend_class = 'WP_FFPC_Backend_' . $wp_ffpc_config['cache_type']; $wp_ffpc_backend = new $backend_class ( $wp_ffpc_config ); //$wp_ffpc_backend = new WP_FFPC_Backend( $wp_ffpc_config ); /* no cache for for logged in users unless it's set identifier cookies are listed in backend as var for easier usage */ if ( !isset($wp_ffpc_config['cache_loggedin']) || $wp_ffpc_config['cache_loggedin'] == 0 || empty($wp_ffpc_config['cache_loggedin']) ) { foreach ($_COOKIE as $n=>$v) { foreach ( $wp_ffpc_backend->cookies as $nocache_cookie ) { if( strpos( $n, $nocache_cookie ) === 0 ) { __wp_ffpc_debug__ ( "No cache for cookie: {$n}, skipping"); return false; } } } } /* will store time of page generation */ $wp_ffpc_gentime = 0; /* backend connection failed, no caching :( */ if ( $wp_ffpc_backend->status() === false ) { __wp_ffpc_debug__ ( "Backend offline"); return false; } /* try to get data & meta keys for current page */ $wp_ffpc_keys = array ( 'meta' => $wp_ffpc_config['prefix_meta'], 'data' => $wp_ffpc_config['prefix_data'] ); $wp_ffpc_values = array(); __wp_ffpc_debug__ ( "Trying to fetch entries"); foreach ( $wp_ffpc_keys as $internal => $key ) { $key = $wp_ffpc_backend->key ( $key ); $value = $wp_ffpc_backend->get ( $key ); if ( ! $value ) { __wp_ffpc_debug__("No cached data foundd"); /* does not matter which is missing, we need both, if one fails, no caching */ wp_ffpc_start(); return; } else { /* store results */ $wp_ffpc_values[ $internal ] = $value; __wp_ffpc_debug__('Got value for ' . $internal); } } /* serve cache 404 status */ if ( isset( $wp_ffpc_values['meta']['status'] ) && $wp_ffpc_values['meta']['status'] == 404 ) { __wp_ffpc_debug__("Serving 404"); header("HTTP/1.1 404 Not Found"); /* if I kill the page serving here, the 404 page will not be showed at all, so we do not do that * flush(); * die(); */ } /* server redirect cache */ if ( isset( $wp_ffpc_values['meta']['redirect'] ) && $wp_ffpc_values['meta']['redirect'] ) { __wp_ffpc_debug__("Serving redirect to {$wp_ffpc_values['meta']['redirect']}"); header('Location: ' . $wp_ffpc_values['meta']['redirect'] ); /* cut the connection as fast as possible */ flush(); die(); } /* page is already cached on client side (chrome likes to do this, anyway, it's quite efficient) */ if ( array_key_exists( "HTTP_IF_MODIFIED_SINCE" , $_SERVER ) && !empty( $wp_ffpc_values['meta']['lastmodified'] ) ) { $if_modified_since = strtotime(preg_replace('/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"])); /* check is cache is still valid */ if ( $if_modified_since >= $wp_ffpc_values['meta']['lastmodified'] ) { __wp_ffpc_debug__("Serving 304 Not Modified"); header("HTTP/1.0 304 Not Modified"); /* connection cut for faster serving */ flush(); die(); } } /*** SERVING CACHED PAGE ***/ /* if we reach this point it means data was found & correct, serve it */ if (!empty ( $wp_ffpc_values['meta']['mime'] ) ) header('Content-Type: ' . $wp_ffpc_values['meta']['mime']); /* set expiry date */ if (isset($wp_ffpc_values['meta']['expire']) && !empty ( $wp_ffpc_values['meta']['expire'] ) ) { $hash = md5 ( $wp_ffpc_uri . $wp_ffpc_values['meta']['expire'] ); switch ($wp_ffpc_values['meta']['type']) { case 'home': case 'feed': $expire = $wp_ffpc_config['browsercache_home']; break; case 'archive': $expire = $wp_ffpc_config['browsercache_taxonomy']; break; case 'single': $expire = $wp_ffpc_config['browsercache']; break; default: $expire = 0; } header('Cache-Control: public,max-age='.$expire.',s-maxage='.$expire.',must-revalidate'); header('Expires: ' . gmdate("D, d M Y H:i:s", $wp_ffpc_values['meta']['expire'] ) . " GMT"); header('ETag: '. $hash); unset($expire, $hash); } else { /* in case there is no expiry set, expire immediately and don't serve Etag; browser cache is disabled */ header('Expires: ' . gmdate("D, d M Y H:i:s", time() ) . " GMT"); /* if I set these, the 304 not modified will never, ever kick in, so not setting these * leaving here as a reminder why it should not be set */ //header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, s-maxage=0, post-check=0, pre-check=0'); //header('Pragma: no-cache'); } /* if shortlinks were set */ if (isset($wp_ffpc_values['meta']['shortlink']) && !empty ( $wp_ffpc_values['meta']['shortlink'] ) ) header( 'Link:<'. $wp_ffpc_values['meta']['shortlink'] .'>; rel=shortlink' ); /* if last modifications were set (for posts & pages) */ if (isset($wp_ffpc_values['meta']['lastmodified']) && !empty($wp_ffpc_values['meta']['lastmodified']) ) header( 'Last-Modified: ' . gmdate("D, d M Y H:i:s", $wp_ffpc_values['meta']['lastmodified'] ). " GMT" ); /* pingback urls, if existx */ if ( isset($wp_ffpc_values['meta']['pingback']) && !empty( $wp_ffpc_values['meta']['pingback'] ) && isset($wp_ffpc_config['pingback_header']) && $wp_ffpc_config['pingback_header'] ) header( 'X-Pingback: ' . $wp_ffpc_values['meta']['pingback'] ); /* for debugging */ if ( isset($wp_ffpc_config['response_header']) && $wp_ffpc_config['response_header'] ) header( 'X-Cache-Engine: WP-FFPC with ' . $wp_ffpc_config['cache_type'] .' via PHP'); /* HTML data */ if ( isset($wp_ffpc_config['generate_time']) && $wp_ffpc_config['generate_time'] == '1' && stripos($wp_ffpc_values['data'], '
close tag = not HTML, also no