Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -126,6 +126,8 @@ |
127 | 127 | private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest; |
128 | 128 | private $mInternalMode, $mSquidMaxage, $mModule; |
129 | 129 | |
| 130 | + private $mCacheControl = array( 'must-revalidate' => true ); |
| 131 | + |
130 | 132 | /** |
131 | 133 | * Constructs an instance of ApiMain that utilizes the module and format specified by $request. |
132 | 134 | * |
— | — | @@ -214,10 +216,22 @@ |
215 | 217 | * Set how long the response should be cached. |
216 | 218 | */ |
217 | 219 | public function setCacheMaxAge( $maxage ) { |
218 | | - $this->mSquidMaxage = $maxage; |
| 220 | + $this->setCacheControl( array( |
| 221 | + 'max-age' => $maxage, |
| 222 | + 's-maxage' => $maxage |
| 223 | + ) ); |
219 | 224 | } |
220 | 225 | |
221 | 226 | /** |
| 227 | + * Set directives (key/value pairs) for the Cache-Control header. |
| 228 | + * Boolean values will be formatted as such, by including or omitting |
| 229 | + * without an equals sign. |
| 230 | + */ |
| 231 | + public function setCacheControl( $directives ) { |
| 232 | + $this->mCacheControl = $directives + $this->mCacheControl; |
| 233 | + } |
| 234 | + |
| 235 | + /** |
222 | 236 | * Create an instance of an output formatter by its name |
223 | 237 | */ |
224 | 238 | public function createPrinterByName( $format ) { |
— | — | @@ -282,22 +296,36 @@ |
283 | 297 | $this->printResult( true ); |
284 | 298 | } |
285 | 299 | |
286 | | - if ( $this->mSquidMaxage == - 1 ) |
287 | | - { |
288 | | - // Nobody called setCacheMaxAge(), use the (s)maxage parameters |
289 | | - $smaxage = $this->getParameter( 'smaxage' ); |
290 | | - $maxage = $this->getParameter( 'maxage' ); |
| 300 | + // If nobody called setCacheMaxAge(), use the (s)maxage parameters |
| 301 | + if ( !isset( $this->mCacheControl['s-maxage'] ) ) { |
| 302 | + $this->mCacheControl['s-maxage'] = $this->getParameter( 'smaxage' ); |
291 | 303 | } |
292 | | - else |
293 | | - $smaxage = $maxage = $this->mSquidMaxage; |
| 304 | + if ( !isset( $this->mCacheControl['max-age'] ) ) { |
| 305 | + $this->mCacheControl['max-age'] = $this->getParameter( 'maxage' ); |
| 306 | + } |
294 | 307 | |
295 | 308 | // Set the cache expiration at the last moment, as any errors may change the expiration. |
296 | 309 | // if $this->mSquidMaxage == 0, the expiry time is set to the first second of unix epoch |
297 | | - $exp = min( $smaxage, $maxage ); |
| 310 | + $exp = min( $this->mCacheControl['s-maxage'], $this->mCacheControl['max-age'] ); |
298 | 311 | $expires = ( $exp == 0 ? 1 : time() + $exp ); |
299 | 312 | header( 'Expires: ' . wfTimestamp( TS_RFC2822, $expires ) ); |
300 | | - header( 'Cache-Control: s-maxage=' . $smaxage . ', must-revalidate, max-age=' . $maxage ); |
301 | 313 | |
| 314 | + // Construct the Cache-Control header |
| 315 | + $ccHeader = ''; |
| 316 | + $separator = ''; |
| 317 | + foreach ( $this->mCacheControl as $name => $value ) { |
| 318 | + if ( is_bool( $value ) ) { |
| 319 | + if ( $value ) { |
| 320 | + $ccHeader .= $separator . $name; |
| 321 | + } |
| 322 | + } else { |
| 323 | + $ccHeader .= $separator . "$name=$value"; |
| 324 | + } |
| 325 | + $separator = ', '; |
| 326 | + } |
| 327 | + |
| 328 | + header( "Cache-Control: $ccHeader" ); |
| 329 | + |
302 | 330 | if ( $this->mPrinter->getIsHtml() ) |
303 | 331 | echo wfReportTime(); |
304 | 332 | |
Index: trunk/phase3/includes/api/ApiOpenSearch.php |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | } |
44 | 44 | |
45 | 45 | public function execute() { |
46 | | - global $wgEnableOpenSearchSuggest; |
| 46 | + global $wgEnableOpenSearchSuggest, $wgSearchSuggestCacheExpiry; |
47 | 47 | $params = $this->extractRequestParams(); |
48 | 48 | $search = $params['search']; |
49 | 49 | $limit = $params['limit']; |
— | — | @@ -55,7 +55,8 @@ |
56 | 56 | else { |
57 | 57 | // Open search results may be stored for a very long |
58 | 58 | // time |
59 | | - $this->getMain()->setCacheMaxAge( 1200 ); |
| 59 | + $this->getMain()->setCacheMaxAge( $wgSearchSuggestCacheExpiry ); |
| 60 | + $this->getMain()->setCacheControl( array( 'must-revalidate' => false ) ); |
60 | 61 | |
61 | 62 | $srchres = PrefixSearch::titleSearch( $search, $limit, |
62 | 63 | $namespaces ); |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -2075,6 +2075,11 @@ |
2076 | 2076 | $wgEnableOpenSearchSuggest = true; |
2077 | 2077 | |
2078 | 2078 | /** |
| 2079 | + * Expiry time for search suggestion responses |
| 2080 | + */ |
| 2081 | +$wgSearchSuggestCacheExpiry = 1200; |
| 2082 | + |
| 2083 | +/** |
2079 | 2084 | * Template for internal MediaWiki suggestion engine, defaults to API action=opensearch |
2080 | 2085 | * |
2081 | 2086 | * Placeholders: {searchTerms}, {namespaces}, {dbname} |