From f9be15fd137f6f4d2769f8c85294c792d8571aaa Mon Sep 17 00:00:00 2001 From: Daniel Kinzler Date: Tue, 15 Aug 2006 21:37:06 +0000 Subject: [PATCH] Added squid cache control to AjaxCachePolicy, similar to what OutputPage does. Experimental. --- includes/AjaxFunctions.php | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/includes/AjaxFunctions.php b/includes/AjaxFunctions.php index a1a400994b..9804a241ba 100644 --- a/includes/AjaxFunctions.php +++ b/includes/AjaxFunctions.php @@ -88,16 +88,41 @@ class AjaxCachePolicy { } function writeHeader() { + global $wgUseSquid, $wgUseESI, $wgSquidMaxage; + header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - if ( is_null( $this->policy ) ) { - // Bust cache in the head + + if ( $this->policy ) { + + # If squid caches are configured, tell them to cache the response, + # and tell the client to always check with the squid. Otherwise, + # tell the client to use a cached copy, without a way to purge it. + + if( $wgUseSquid ) { + + # Expect explicite purge of the proxy cache, but require end user agents + # to revalidate against the proxy on each visit. + # Surrogate-Control controls our Squid, Cache-Control downstream caches + + if ( $wgUseESI ) { + header( 'Surrogate-Control: max-age='.$this->policy.', content="ESI/1.0"'); + header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' ); + } else { + header( 'Cache-Control: s-maxage='.$this->policy.', must-revalidate, max-age=0' ); + } + + } else { + + # Let the client do the caching. Cache is not purged. + header ("Expires: " . gmdate( "D, d M Y H:i:s", time() + $this->policy ) . " GMT"); + header ("Cache-Control: s-max-age={$this->policy},public,max-age={$this->policy}"); + } + + } else { + # always expired, always modified header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past - // always modified header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 - } else { - header ("Expires: " . gmdate( "D, d M Y H:i:s", time() + $this->policy ) . " GMT"); - header ("Cache-Control: s-max-age={$this->policy},public,max-age={$this->policy}"); } if ( $this->vary ) { -- 2.20.1